use more precise addr names
This commit is contained in:
parent
38054cf331
commit
73998a9403
|
@ -4,12 +4,13 @@ import (
|
||||||
"fmt"
|
"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)
|
n := len(payload)
|
||||||
header := []byte(fmt.Sprintf(
|
header := []byte(fmt.Sprintf(
|
||||||
"%s,%s,%d,%d,%s,%d,%s,\n",
|
"%s,%s,%d,%d,%s,%d,%s,\n",
|
||||||
src.family, src.addr, src.port,
|
id.family, id.addr, id.port,
|
||||||
n, dst.scheme, dst.port, domain,
|
n, tun.scheme, tun.port, domain,
|
||||||
))
|
))
|
||||||
raw := []byte{255 - 1, byte(len(header))}
|
raw := []byte{255 - 1, byte(len(header))}
|
||||||
header = append(raw, header...)
|
header = append(raw, header...)
|
||||||
|
|
|
@ -6,13 +6,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEncodeDataMessage(t *testing.T) {
|
func TestEncodeDataMessage(t *testing.T) {
|
||||||
src := Addr{
|
id := Addr{
|
||||||
family: "IPv4",
|
family: "IPv4",
|
||||||
addr: "192.168.1.101",
|
addr: "192.168.1.101",
|
||||||
port: 6743,
|
port: 6743,
|
||||||
}
|
}
|
||||||
dst := Addr{
|
tun := Addr{
|
||||||
family: src.family,
|
family: id.family,
|
||||||
port: 80,
|
port: 80,
|
||||||
scheme: "http",
|
scheme: "http",
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func TestEncodeDataMessage(t *testing.T) {
|
||||||
//header = append([]byte{V1, byte(len(header))}, header...)
|
//header = append([]byte{V1, byte(len(header))}, header...)
|
||||||
header = append([]byte{254, 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 {
|
if nil != err {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue