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
|
|
|
|
|
|
|
"v2ray.com/core/common"
|
|
|
|
)
|
2016-12-08 10:27:41 -05:00
|
|
|
|
|
|
|
type PacketHeader interface {
|
2018-04-02 14:00:50 -04:00
|
|
|
Size() int32
|
2016-12-09 06:08:25 -05:00
|
|
|
Write([]byte) (int, error)
|
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
|
|
|
}
|