mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-10 07:30:27 +00:00
let the peer's linkLoop call close if the peer receives no announcements for too long
This commit is contained in:
parent
6026e0a014
commit
80f893aac3
@ -82,6 +82,8 @@ type peer struct {
|
|||||||
throttle uint8
|
throttle uint8
|
||||||
// Called when a peer is removed, to close the underlying connection, or via admin api
|
// Called when a peer is removed, to close the underlying connection, or via admin api
|
||||||
close func()
|
close func()
|
||||||
|
// To allow the peer to call close if idle for too long
|
||||||
|
lastAnc time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
const peer_Throttle = 1
|
const peer_Throttle = 1
|
||||||
@ -106,13 +108,10 @@ func (p *peer) updateBandwidth(bytes int, duration time.Duration) {
|
|||||||
|
|
||||||
func (ps *peers) newPeer(box *boxPubKey,
|
func (ps *peers) newPeer(box *boxPubKey,
|
||||||
sig *sigPubKey) *peer {
|
sig *sigPubKey) *peer {
|
||||||
//in <-chan []byte,
|
|
||||||
//out chan<- []byte) *peer {
|
|
||||||
p := peer{box: *box,
|
p := peer{box: *box,
|
||||||
sig: *sig,
|
sig: *sig,
|
||||||
shared: *getSharedKey(&ps.core.boxPriv, box),
|
shared: *getSharedKey(&ps.core.boxPriv, box),
|
||||||
//in: in,
|
lastAnc: time.Now(),
|
||||||
//out: out,
|
|
||||||
core: ps.core}
|
core: ps.core}
|
||||||
ps.mutex.Lock()
|
ps.mutex.Lock()
|
||||||
defer ps.mutex.Unlock()
|
defer ps.mutex.Unlock()
|
||||||
@ -165,7 +164,10 @@ func (p *peer) linkLoop(in <-chan []byte) {
|
|||||||
}
|
}
|
||||||
p.handleLinkTraffic(packet)
|
p.handleLinkTraffic(packet)
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
{
|
if time.Since(p.lastAnc) > 16*time.Second && p.close != nil {
|
||||||
|
// Seems to have timed out, try to trigger a close
|
||||||
|
p.close()
|
||||||
|
}
|
||||||
p.throttle = 0
|
p.throttle = 0
|
||||||
if p.port == 0 {
|
if p.port == 0 {
|
||||||
continue
|
continue
|
||||||
@ -192,7 +194,6 @@ func (p *peer) linkLoop(in <-chan []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (p *peer) handlePacket(packet []byte, linkIn chan<- []byte) {
|
func (p *peer) handlePacket(packet []byte, linkIn chan<- []byte) {
|
||||||
pType, pTypeLen := wire_decode_uint64(packet)
|
pType, pTypeLen := wire_decode_uint64(packet)
|
||||||
@ -217,6 +218,10 @@ func (p *peer) handlePacket(packet []byte, linkIn chan<- []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *peer) handleTraffic(packet []byte, pTypeLen int) {
|
func (p *peer) handleTraffic(packet []byte, pTypeLen int) {
|
||||||
|
if p.msgAnc == nil {
|
||||||
|
// Drop traffic until the peer manages to send us at least one anc
|
||||||
|
return
|
||||||
|
}
|
||||||
ttl, ttlLen := wire_decode_uint64(packet[pTypeLen:])
|
ttl, ttlLen := wire_decode_uint64(packet[pTypeLen:])
|
||||||
ttlBegin := pTypeLen
|
ttlBegin := pTypeLen
|
||||||
ttlEnd := pTypeLen + ttlLen
|
ttlEnd := pTypeLen + ttlLen
|
||||||
@ -299,6 +304,7 @@ func (p *peer) handleSwitchAnnounce(packet []byte) {
|
|||||||
}
|
}
|
||||||
p.msgAnc = &anc
|
p.msgAnc = &anc
|
||||||
p.processSwitchMessage()
|
p.processSwitchMessage()
|
||||||
|
p.lastAnc = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *peer) requestHop(hop uint64) {
|
func (p *peer) requestHop(hop uint64) {
|
||||||
|
@ -104,6 +104,7 @@ func generateConfig(isAutoconf bool) *nodeConfig {
|
|||||||
cfg.SigPub = hex.EncodeToString(spub[:])
|
cfg.SigPub = hex.EncodeToString(spub[:])
|
||||||
cfg.SigPriv = hex.EncodeToString(spriv[:])
|
cfg.SigPriv = hex.EncodeToString(spriv[:])
|
||||||
cfg.Peers = []string{}
|
cfg.Peers = []string{}
|
||||||
|
cfg.PeerBoxPubs = []string{}
|
||||||
cfg.Multicast = true
|
cfg.Multicast = true
|
||||||
cfg.LinkLocal = ""
|
cfg.LinkLocal = ""
|
||||||
cfg.IfName = core.DEBUG_GetTUNDefaultIfName()
|
cfg.IfName = core.DEBUG_GetTUNDefaultIfName()
|
||||||
|
Loading…
Reference in New Issue
Block a user