1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-07 00:40:26 +08:00

add link rep

This commit is contained in:
fumiama
2021-12-30 16:35:37 +08:00
parent 66c200b708
commit db5ac5787e
2 changed files with 10 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/fumiama/WireGold/gold/head"
"github.com/fumiama/WireGold/helper"
)
// Link 是本机到 peer 的连接抽象
@@ -100,3 +101,11 @@ func (l *Link) Write(p *head.Packet, istransfer bool) (n int, err error) {
}
return
}
func (l *Link) String() (n string) {
n = "default"
if l.pubk != nil {
n = helper.BytesToString(l.pubk[:24])
}
return
}

View File

@@ -5,7 +5,6 @@ import (
"net"
"sync"
"github.com/fumiama/WireGold/helper"
"github.com/sirupsen/logrus"
)
@@ -85,11 +84,7 @@ func (r *Router) SetItem(ip *net.IPNet, l *Link) {
copy(r.list[i+1:], r.list[i:len(r.list)-1])
r.list[i] = ip
r.table[ip.String()] = l
lnkname := "default"
if l.pubk != nil {
lnkname = helper.BytesToString(l.pubk[:24])
}
logrus.Infoln("[router] add route in link", lnkname, "to", ip, "-->", l.peerip)
logrus.Infoln("[router] add route in link", l, "to", ip, "-->", l.peerip)
break
}
}