1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-26 03:55:26 -05:00

rename IPNet to IPNetTable

This commit is contained in:
Darien Raymond
2017-08-29 13:51:09 +02:00
parent fee3042239
commit 815019f6da
5 changed files with 26 additions and 20 deletions

View File

@@ -5,17 +5,17 @@ import (
"net"
)
type IPNet struct {
type IPNetTable struct {
cache map[uint32]byte
}
func NewIPNet() *IPNet {
return &IPNet{
func NewIPNetTable() *IPNetTable {
return &IPNetTable{
cache: make(map[uint32]byte, 1024),
}
}
func ipToUint32(ip net.IP) uint32 {
func ipToUint32(ip IP) uint32 {
value := uint32(0)
for _, b := range []byte(ip) {
value <<= 8
@@ -32,7 +32,7 @@ func ipMaskToByte(mask net.IPMask) byte {
return value
}
func (n *IPNet) Add(ipNet *net.IPNet) {
func (n *IPNetTable) Add(ipNet *net.IPNet) {
ipv4 := ipNet.IP.To4()
if ipv4 == nil {
// For now, we don't support IPv6
@@ -42,7 +42,7 @@ func (n *IPNet) Add(ipNet *net.IPNet) {
n.AddIP(ipv4, mask)
}
func (n *IPNet) AddIP(ip []byte, mask byte) {
func (n *IPNetTable) AddIP(ip []byte, mask byte) {
k := ipToUint32(ip)
existing, found := n.cache[k]
if !found || existing > mask {
@@ -50,7 +50,7 @@ func (n *IPNet) AddIP(ip []byte, mask byte) {
}
}
func (n *IPNet) Contains(ip net.IP) bool {
func (n *IPNetTable) Contains(ip net.IP) bool {
ipv4 := ip.To4()
if ipv4 == nil {
return false
@@ -77,6 +77,6 @@ func (n *IPNet) Contains(ip net.IP) bool {
return false
}
func (n *IPNet) IsEmpty() bool {
func (n *IPNetTable) IsEmpty() bool {
return len(n.cache) == 0
}