github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/proxy/shadowsocksr/obfs/base.go (about) 1 package obfs 2 3 import ( 4 "fmt" 5 "net" 6 7 "github.com/Asutorufa/yuhaiin/pkg/net/proxy/shadowsocksr/cipher" 8 ) 9 10 var ObfsMethod = map[string]struct { 11 overhead int 12 stream func(net.Conn, Obfs) net.Conn 13 }{ 14 "http_post": {0, newHttpPost}, 15 "http_simple": {0, newHttpSimple}, 16 "plain": {0, newPlain}, 17 "random_head": {0, newRandomHead}, 18 "tls1.2_ticket_auth": {5, newTLS12TicketAuth}, 19 "tls1.2_ticket_fastauth": {5, newTLS12TicketAuth}, 20 } 21 22 type Obfs struct { 23 *cipher.Cipher 24 Name string 25 Host string 26 Port string 27 Param string 28 } 29 30 func (o Obfs) Stream(c net.Conn) (net.Conn, error) { 31 z, ok := ObfsMethod[o.Name] 32 if !ok { 33 return nil, fmt.Errorf("obfs %s not found", o.Name) 34 } 35 return z.stream(c, o), nil 36 } 37 38 func (o Obfs) Overhead() int { 39 z, ok := ObfsMethod[o.Name] 40 if !ok { 41 return -1 42 } 43 return z.overhead 44 }