1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-11 20:20:27 +08:00
Files
WireGold/gold/link/router.go
2021-10-25 21:35:51 +08:00

34 lines
627 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package link
import (
"net"
"sync"
)
var (
routetable = make(map[string][]*Link)
routetablemu sync.RWMutex
)
// Accept 判断是否应当接受 ip 发来的包
func (l *Link) Accept(ip net.IP) bool {
for _, cidr := range l.allowedips {
if cidr.Contains(ip) {
return true
}
}
return false
}
// IsToMe 判断是否是发给自己的包
func (l *Link) IsToMe(ip net.IP) bool {
return ip.Equal(me)
}
// NextHop 得到前往 ip 的下一跳的 link
func (l *Link) NextHop(ip net.IP) *Link {
// TODO: 遍历 routetable得到正确的下一跳
// 注意使用 routetablemu 读写锁避免竞争
return l
}