You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/net/network.go

76 lines
1.3 KiB

9 years ago
package net
import (
"strings"
)
8 years ago
func ParseNetwork(nwStr string) Network {
if network, found := Network_value[nwStr]; found {
return Network(network)
}
switch strings.ToLower(nwStr) {
case "tcp":
return Network_TCP
case "udp":
return Network_UDP
default:
return Network_Unknown
}
}
9 years ago
7 years ago
func (n Network) AsList() *NetworkList {
return &NetworkList{
7 years ago
Network: []Network{n},
}
}
7 years ago
func (n Network) SystemString() string {
switch n {
8 years ago
case Network_TCP:
8 years ago
return "tcp"
case Network_UDP:
8 years ago
return "udp"
default:
return "unknown"
}
}
7 years ago
func (n Network) URLPrefix() string {
switch n {
8 years ago
case Network_TCP:
return "tcp"
case Network_UDP:
return "udp"
default:
return "unknown"
}
}
func HasNetwork(list []Network, network Network) bool {
for _, value := range list {
if string(value) == string(network) {
return true
}
}
return false
}
8 years ago
// HasNetwork returns true if the given network is in v NetworkList.
7 years ago
func (l NetworkList) HasNetwork(network Network) bool {
for _, value := range l.Network {
if string(value) == string(network) {
return true
}
}
return false
9 years ago
}
7 years ago
func (l NetworkList) Get(idx int) Network {
return l.Network[idx]
}
8 years ago
// Size returns the number of networks in this network list.
7 years ago
func (l NetworkList) Size() int {
return len(l.Network)
}