diff --git a/mplexer/packer/packer.go b/mplexer/packer/packer.go index b4c2ef2..f0ce543 100644 --- a/mplexer/packer/packer.go +++ b/mplexer/packer/packer.go @@ -4,12 +4,13 @@ import ( "fmt" ) -func Encode(src, dst Addr, domain string, payload []byte) ([]byte, []byte, error) { +// Encode creates an MPLEXY V1 header for the given addresses and payload +func Encode(id, tun Addr, domain string, payload []byte) ([]byte, []byte, error) { n := len(payload) header := []byte(fmt.Sprintf( "%s,%s,%d,%d,%s,%d,%s,\n", - src.family, src.addr, src.port, - n, dst.scheme, dst.port, domain, + id.family, id.addr, id.port, + n, tun.scheme, tun.port, domain, )) raw := []byte{255 - 1, byte(len(header))} header = append(raw, header...) diff --git a/mplexer/packer/packer_test.go b/mplexer/packer/packer_test.go index 2c879d4..e59606c 100644 --- a/mplexer/packer/packer_test.go +++ b/mplexer/packer/packer_test.go @@ -6,13 +6,13 @@ import ( ) func TestEncodeDataMessage(t *testing.T) { - src := Addr{ + id := Addr{ family: "IPv4", addr: "192.168.1.101", port: 6743, } - dst := Addr{ - family: src.family, + tun := Addr{ + family: id.family, port: 80, scheme: "http", } @@ -23,7 +23,7 @@ func TestEncodeDataMessage(t *testing.T) { //header = append([]byte{V1, byte(len(header))}, header...) header = append([]byte{254, byte(len(header))}, header...) - h, b, err := Encode(src, dst, domain, payload) + h, b, err := Encode(id, tun, domain, payload) if nil != err { t.Fatal(err) }