github.com/kelleygo/clashcore@v1.0.2/transport/ssr/obfs/obfs.go (about)

     1  package obfs
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"net"
     7  )
     8  
     9  var (
    10  	errTLS12TicketAuthIncorrectMagicNumber = errors.New("tls1.2_ticket_auth incorrect magic number")
    11  	errTLS12TicketAuthTooShortData         = errors.New("tls1.2_ticket_auth too short data")
    12  	errTLS12TicketAuthHMACError            = errors.New("tls1.2_ticket_auth hmac verifying failed")
    13  )
    14  
    15  type authData struct {
    16  	clientID [32]byte
    17  }
    18  
    19  type Obfs interface {
    20  	StreamConn(net.Conn) net.Conn
    21  }
    22  
    23  type obfsCreator func(b *Base) Obfs
    24  
    25  var obfsList = make(map[string]struct {
    26  	overhead int
    27  	new      obfsCreator
    28  })
    29  
    30  func register(name string, c obfsCreator, o int) {
    31  	obfsList[name] = struct {
    32  		overhead int
    33  		new      obfsCreator
    34  	}{overhead: o, new: c}
    35  }
    36  
    37  func PickObfs(name string, b *Base) (Obfs, int, error) {
    38  	if choice, ok := obfsList[name]; ok {
    39  		return choice.new(b), choice.overhead, nil
    40  	}
    41  	return nil, 0, fmt.Errorf("Obfs %s not supported", name)
    42  }