use more precise addr names

This commit is contained in:
AJ ONeal 2020-05-19 03:36:46 -06:00
parent 38054cf331
commit 73998a9403
2 changed files with 8 additions and 7 deletions

View File

@ -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...)

View File

@ -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)
}