Skip to content
Snippets Groups Projects
Commit 8f35fb6d authored by cyberta's avatar cyberta
Browse files

ensure kcp configs are serialized and deserialized correctly. Adds an test...

ensure kcp configs are serialized and deserialized correctly. Adds an test with test json data derived from a java model class, in order to ensure the interoperability
parent ea3859ee
Branches
Tags
1 merge request!73ensure kcp configs are serialized and deserialized correctly
Checking pipeline status
package client
import (
"encoding/json"
"testing"
)
// This json was generated from the java model classes
var expected = `{"hopping_config":{"enabled":false,"hop_jitter":10,"min_hop_seconds":10,"obfs4_certs":["XXXXYYYYZZZZ"],"port_count":0,"port_seed":0,"proxy_addr":"127.0.0.1:8080","remotes":["37.218.4.12"]},"kcp_config":{"mtu":1400,"disable_flow_control":true,"enabled":true,"interval":10,"no_delay":true,"read_buffer":16777216,"receive_window_size":65535,"resend":2,"send_window_size":65535,"write_buffer":16777216},"obfs4_cert":"XXXYYYYZZZZZ","proxy_addr":"127.0.0.1:8080","remote_ip":"37.218.4.12","remote_port":"4431"}`
func TestJsonFormattingEnsureFFIInterop(t *testing.T) {
config := Config{}
err := json.Unmarshal([]byte(expected), &config)
if err != nil {
t.Error("unexpected marshalling error: ", err)
}
if !config.KCPConfig.DisableFlowControl {
t.Error("DisableFlowControl should be false")
}
if config.KCPConfig.MTU != 1400 {
t.Error("Unexpected MTU")
}
}
......@@ -20,16 +20,16 @@ const (
// https://github.com/skywind3000/kcp/blob/master/README.en.md#protocol-configuration
type KCPConfig struct {
Enabled bool
SendWindowSize int
ReceiveWindowSize int
ReadBuffer int
WriteBuffer int
NoDelay bool
Interval int
Resend int
DisableFlowControl bool
MTU int
Enabled bool `json:"enabled"`
SendWindowSize int `json:"send_window_size"`
ReceiveWindowSize int `json:"receive_window_size"`
ReadBuffer int `json:"read_buffer"`
WriteBuffer int `json:"write_buffer"`
NoDelay bool `json:"no_delay"`
Interval int `json:"interval"`
Resend int `json:"resend"`
DisableFlowControl bool `json:"disable_flow_control"`
MTU int `json:"mtu"`
}
func DefaultKCPConfig() *KCPConfig {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment