2015-10-30 10:56:46 -04:00
|
|
|
package net
|
|
|
|
|
2016-01-15 08:34:33 -05:00
|
|
|
import (
|
2016-05-24 16:41:51 -04:00
|
|
|
"strings"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/common/collect"
|
2016-01-15 08:34:33 -05:00
|
|
|
)
|
|
|
|
|
2015-10-30 10:56:46 -04:00
|
|
|
const (
|
2016-02-06 05:09:53 -05:00
|
|
|
// TCPNetwork represents the TCP network.
|
2015-10-30 10:56:46 -04:00
|
|
|
TCPNetwork = Network("tcp")
|
2016-02-06 05:09:53 -05:00
|
|
|
|
|
|
|
// UDPNetwork represents the UDP network.
|
2015-10-30 10:56:46 -04:00
|
|
|
UDPNetwork = Network("udp")
|
2016-06-14 16:54:08 -04:00
|
|
|
|
|
|
|
// KCPNetwork represents the KCP network.
|
|
|
|
KCPNetwork = Network("kcp")
|
2016-08-13 09:32:47 -04:00
|
|
|
|
|
|
|
// WSNetwork represents the Websocket over HTTP network.
|
|
|
|
WSNetwork = Network("ws")
|
2015-10-30 10:56:46 -04:00
|
|
|
)
|
|
|
|
|
2016-02-06 05:09:53 -05:00
|
|
|
// Network represents a communication network on internet.
|
2016-05-24 16:41:51 -04:00
|
|
|
type Network string
|
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-06-03 18:38:22 -04:00
|
|
|
func (this Network) String() string {
|
|
|
|
return string(this)
|
|
|
|
}
|
|
|
|
|
2016-02-06 05:09:53 -05:00
|
|
|
// NetworkList is a list of Networks.
|
2016-01-15 08:34:33 -05:00
|
|
|
type NetworkList []Network
|
|
|
|
|
2016-02-06 05:09:53 -05:00
|
|
|
// NewNetworkList construsts a NetWorklist from the given StringListeralList.
|
2016-05-24 16:41:51 -04:00
|
|
|
func NewNetworkList(networks collect.StringList) NetworkList {
|
2016-01-15 09:23:12 -05:00
|
|
|
list := NetworkList(make([]Network, networks.Len()))
|
2016-01-15 08:34:33 -05:00
|
|
|
for idx, network := range networks {
|
2016-05-24 16:41:51 -04:00
|
|
|
list[idx] = Network(strings.ToLower(strings.TrimSpace(network)))
|
2016-01-15 08:34:33 -05:00
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2016-02-06 05:09:53 -05:00
|
|
|
// HashNetwork returns true if the given network is in this NetworkList.
|
2016-01-15 08:34:33 -05:00
|
|
|
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
|
|
|
}
|