1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-04 21:15:24 +00:00
v2fly/common/net/network.go

44 lines
1.0 KiB
Go
Raw Normal View History

2015-10-30 14:56:46 +00:00
package net
2016-01-15 13:34:33 +00:00
import (
2016-01-15 14:23:12 +00:00
"github.com/v2ray/v2ray-core/common/serial"
2016-01-15 13:34:33 +00:00
)
2015-10-30 14:56:46 +00:00
const (
2016-02-06 10:09:53 +00:00
// TCPNetwork represents the TCP network.
2015-10-30 14:56:46 +00:00
TCPNetwork = Network("tcp")
2016-02-06 10:09:53 +00:00
// UDPNetwork represents the UDP network.
2015-10-30 14:56:46 +00:00
UDPNetwork = Network("udp")
)
2016-02-06 10:09:53 +00:00
// Network represents a communication network on internet.
2016-01-15 14:23:12 +00:00
type Network serial.StringLiteral
2015-10-30 14:56:46 +00:00
2016-01-17 15:20:49 +00:00
func (this Network) AsList() *NetworkList {
list := NetworkList([]Network{this})
return &list
}
2016-02-06 10:09:53 +00:00
// NetworkList is a list of Networks.
2016-01-15 13:34:33 +00:00
type NetworkList []Network
2016-02-06 10:09:53 +00:00
// NewNetworkList construsts a NetWorklist from the given StringListeralList.
2016-01-15 14:23:12 +00:00
func NewNetworkList(networks serial.StringLiteralList) NetworkList {
list := NetworkList(make([]Network, networks.Len()))
2016-01-15 13:34:33 +00:00
for idx, network := range networks {
2016-01-15 14:23:12 +00:00
list[idx] = Network(network.TrimSpace().ToLower())
2016-01-15 13:34:33 +00:00
}
return list
}
2016-02-06 10:09:53 +00:00
// HashNetwork returns true if the given network is in this NetworkList.
2016-01-15 13:34:33 +00:00
func (this *NetworkList) HasNetwork(network Network) bool {
for _, value := range *this {
if string(value) == string(network) {
return true
}
}
return false
2015-10-30 14:56:46 +00:00
}