2015-10-30 10:56:46 -04:00
|
|
|
package net
|
|
|
|
|
2016-01-15 08:34:33 -05:00
|
|
|
import (
|
2016-01-15 09:23:12 -05:00
|
|
|
"github.com/v2ray/v2ray-core/common/serial"
|
2016-01-15 08:34:33 -05:00
|
|
|
)
|
|
|
|
|
2015-10-30 10:56:46 -04:00
|
|
|
const (
|
|
|
|
TCPNetwork = Network("tcp")
|
|
|
|
UDPNetwork = Network("udp")
|
|
|
|
)
|
|
|
|
|
2016-01-15 09:23:12 -05:00
|
|
|
type Network serial.StringLiteral
|
2015-10-30 10:56:46 -04:00
|
|
|
|
2016-01-17 10:20:49 -05:00
|
|
|
func (this Network) AsList() *NetworkList {
|
|
|
|
list := NetworkList([]Network{this})
|
|
|
|
return &list
|
|
|
|
}
|
|
|
|
|
2016-01-15 08:34:33 -05:00
|
|
|
type NetworkList []Network
|
|
|
|
|
2016-01-15 09:23:12 -05:00
|
|
|
func NewNetworkList(networks serial.StringLiteralList) NetworkList {
|
|
|
|
list := NetworkList(make([]Network, networks.Len()))
|
2016-01-15 08:34:33 -05:00
|
|
|
for idx, network := range networks {
|
2016-01-15 09:23:12 -05:00
|
|
|
list[idx] = Network(network.TrimSpace().ToLower())
|
2016-01-15 08:34:33 -05:00
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *NetworkList) HasNetwork(network Network) bool {
|
|
|
|
for _, value := range *this {
|
|
|
|
if string(value) == string(network) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2015-10-30 10:56:46 -04:00
|
|
|
}
|