2016-12-08 10:27:41 -05:00
|
|
|
package internet
|
|
|
|
|
2017-01-12 16:47:10 -05:00
|
|
|
import (
|
|
|
|
"context"
|
2017-02-23 16:34:02 -05:00
|
|
|
"net"
|
2017-01-12 16:47:10 -05:00
|
|
|
|
2021-02-16 15:31:50 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v4/common"
|
2017-01-12 16:47:10 -05:00
|
|
|
)
|
2016-12-08 10:27:41 -05:00
|
|
|
|
|
|
|
type PacketHeader interface {
|
2018-04-02 14:00:50 -04:00
|
|
|
Size() int32
|
2018-11-02 16:34:04 -04:00
|
|
|
Serialize([]byte)
|
2016-12-08 10:27:41 -05:00
|
|
|
}
|
|
|
|
|
2017-01-12 16:47:10 -05:00
|
|
|
func CreatePacketHeader(config interface{}) (PacketHeader, error) {
|
|
|
|
header, err := common.CreateObject(context.Background(), config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-12-08 10:27:41 -05:00
|
|
|
}
|
2017-02-23 16:34:02 -05:00
|
|
|
if h, ok := header.(PacketHeader); ok {
|
2017-01-12 16:47:10 -05:00
|
|
|
return h, nil
|
2016-12-08 10:27:41 -05:00
|
|
|
}
|
2017-04-09 09:04:04 -04:00
|
|
|
return nil, newError("not a packet header")
|
2017-02-23 16:34:02 -05: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
|
|
|
|
}
|
2017-04-09 09:04:04 -04:00
|
|
|
return nil, newError("not a ConnectionAuthenticator")
|
2016-12-08 10:27:41 -05:00
|
|
|
}
|