2016-12-08 10:27:41 -05:00
|
|
|
package internet
|
|
|
|
|
2017-01-12 16:47:10 -05:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"v2ray.com/core/common"
|
|
|
|
)
|
2016-12-08 10:27:41 -05:00
|
|
|
|
|
|
|
type PacketHeader interface {
|
|
|
|
Size() int
|
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-01-12 16:47:10 -05:00
|
|
|
switch h := header.(type) {
|
|
|
|
case PacketHeader:
|
|
|
|
return h, nil
|
|
|
|
default:
|
|
|
|
return nil, errors.New("Internet: Not a packet header.")
|
2016-12-08 10:27:41 -05:00
|
|
|
}
|
|
|
|
}
|