telebit/mplexer/packer.go

20 lines
454 B
Go
Raw Normal View History

2020-05-22 10:41:24 +00:00
package telebit
2020-05-18 08:43:06 +00:00
import (
2020-05-18 09:30:22 +00:00
"fmt"
2020-05-18 08:43:06 +00:00
)
2020-05-19 09:36:46 +00:00
// Encode creates an MPLEXY V1 header for the given addresses and payload
2020-05-21 10:29:05 +00:00
func Encode(payload []byte, id, tun Addr) ([]byte, []byte, error) {
2020-05-18 09:30:22 +00:00
n := len(payload)
2020-05-21 10:29:05 +00:00
domain := tun.addr
2020-05-18 09:30:22 +00:00
header := []byte(fmt.Sprintf(
"%s,%s,%d,%d,%s,%d,%s,\n",
2020-05-19 09:36:46 +00:00
id.family, id.addr, id.port,
n, tun.scheme, tun.port, domain,
2020-05-18 09:30:22 +00:00
))
2020-05-18 08:43:06 +00:00
raw := []byte{255 - 1, byte(len(header))}
header = append(raw, header...)
2020-05-18 09:30:22 +00:00
return header, payload, nil
2020-05-18 08:43:06 +00:00
}