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

50 lines
1.1 KiB

9 years ago
package net
import (
"strings"
"github.com/v2ray/v2ray-core/common/collect"
)
9 years ago
const (
9 years ago
// TCPNetwork represents the TCP network.
9 years ago
TCPNetwork = Network("tcp")
9 years ago
// UDPNetwork represents the UDP network.
9 years ago
UDPNetwork = Network("udp")
)
9 years ago
// Network represents a communication network on internet.
type Network string
9 years ago
func (this Network) AsList() *NetworkList {
list := NetworkList([]Network{this})
return &list
}
func (this Network) String() string {
return string(this)
}
9 years ago
// NetworkList is a list of Networks.
type NetworkList []Network
9 years ago
// NewNetworkList construsts a NetWorklist from the given StringListeralList.
func NewNetworkList(networks collect.StringList) NetworkList {
list := NetworkList(make([]Network, networks.Len()))
for idx, network := range networks {
list[idx] = Network(strings.ToLower(strings.TrimSpace(network)))
}
return list
}
9 years ago
// HashNetwork returns true if the given network is in this NetworkList.
func (this *NetworkList) HasNetwork(network Network) bool {
for _, value := range *this {
if string(value) == string(network) {
return true
}
}
return false
9 years ago
}