1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-07-13 12:40:12 -04:00

rename IP to CIDR in router

This commit is contained in:
Darien Raymond
2016-10-18 16:42:22 +02:00
parent 2af4b16913
commit e13c97d162
18 changed files with 169 additions and 127 deletions

View File

@@ -13,12 +13,8 @@ type IPNet struct {
}
func NewIPNet() *IPNet {
return NewIPNetInitialValue(make(map[uint32]byte, 1024))
}
func NewIPNetInitialValue(data map[uint32]byte) *IPNet {
return &IPNet{
cache: data,
cache: make(map[uint32]byte, 1024),
}
}
@@ -45,11 +41,15 @@ func (this *IPNet) Add(ipNet *net.IPNet) {
// For now, we don't support IPv6
return
}
value := ipToUint32(ipv4)
mask := ipMaskToByte(ipNet.Mask)
existing, found := this.cache[value]
this.AddIP(ipv4, mask)
}
func (this *IPNet) AddIP(ip []byte, mask byte) {
k := ipToUint32(ip)
existing, found := this.cache[k]
if !found || existing > mask {
this.cache[value] = mask
this.cache[k] = mask
}
}
@@ -80,12 +80,8 @@ func (this *IPNet) Contains(ip net.IP) bool {
return false
}
func (this *IPNet) Serialize() []uint32 {
content := make([]uint32, 0, 2*len(this.cache))
for key, value := range this.cache {
content = append(content, uint32(key), uint32(value))
}
return content
func (this *IPNet) IsEmpty() bool {
return len(this.cache) == 0
}
func init() {

View File

@@ -16,8 +16,10 @@ var _ = math.Inf
type Network int32
const (
Network_Unknown Network = 0
Network_RawTCP Network = 1
Network_Unknown Network = 0
// Native TCP provided by system.
Network_RawTCP Network = 1
// V2Ray specific TCP.
Network_TCP Network = 2
Network_UDP Network = 3
Network_KCP Network = 4