2020-11-25 11:01:53 +00:00
|
|
|
package internet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
|
2020-12-04 01:36:16 +00:00
|
|
|
"github.com/xtls/xray-core/common"
|
2024-06-29 18:32:57 +00:00
|
|
|
"github.com/xtls/xray-core/common/errors"
|
2020-11-25 11:01:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PacketHeader interface {
|
|
|
|
Size() int32
|
|
|
|
Serialize([]byte)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreatePacketHeader(config interface{}) (PacketHeader, error) {
|
|
|
|
header, err := common.CreateObject(context.Background(), config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if h, ok := header.(PacketHeader); ok {
|
|
|
|
return h, nil
|
|
|
|
}
|
2024-06-29 18:32:57 +00:00
|
|
|
return nil, errors.New("not a packet header")
|
2020-11-25 11:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ConnectionAuthenticator interface {
|
|
|
|
Client(net.Conn) net.Conn
|
|
|
|
Server(net.Conn) net.Conn
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateConnectionAuthenticator(config interface{}) (ConnectionAuthenticator, error) {
|
|
|
|
auth, err := common.CreateObject(context.Background(), config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if a, ok := auth.(ConnectionAuthenticator); ok {
|
|
|
|
return a, nil
|
|
|
|
}
|
2024-06-29 18:32:57 +00:00
|
|
|
return nil, errors.New("not a ConnectionAuthenticator")
|
2020-11-25 11:01:53 +00:00
|
|
|
}
|