mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 04:51:38 +00:00
misc other fixes
This commit is contained in:
parent
2dc136f94a
commit
2d64a6380a
@ -102,11 +102,12 @@ func (c *Conn) search() error {
|
|||||||
if sinfo != nil {
|
if sinfo != nil {
|
||||||
// Need to clean up to avoid a session leak
|
// Need to clean up to avoid a session leak
|
||||||
sinfo.cancel.Cancel(nil)
|
sinfo.cancel.Cancel(nil)
|
||||||
|
sinfo.sessions.removeSession(sinfo)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if sinfo != nil {
|
if sinfo != nil {
|
||||||
// Finish initializing the session
|
// Finish initializing the session
|
||||||
sinfo.conn = c
|
sinfo.setConn(nil, c)
|
||||||
}
|
}
|
||||||
c.session = sinfo
|
c.session = sinfo
|
||||||
err = e
|
err = e
|
||||||
|
@ -416,8 +416,11 @@ func (sinfo *sessionInfo) _updateNonce(theirNonce *crypto.BoxNonce) {
|
|||||||
// Called after coord changes, so attemtps to use a session will trigger a new ping and notify the remote end of the coord change.
|
// Called after coord changes, so attemtps to use a session will trigger a new ping and notify the remote end of the coord change.
|
||||||
// Only call this from the router actor.
|
// Only call this from the router actor.
|
||||||
func (ss *sessions) reset() {
|
func (ss *sessions) reset() {
|
||||||
for _, sinfo := range ss.sinfos {
|
for _, _sinfo := range ss.sinfos {
|
||||||
sinfo.reset = true
|
sinfo := _sinfo // So we can safely put it in a closure
|
||||||
|
sinfo.Act(ss.router, func() {
|
||||||
|
sinfo.reset = true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,12 +477,6 @@ func (sinfo *sessionInfo) _recvPacket(p *wire_trafficPacket) {
|
|||||||
util.PutBytes(bs)
|
util.PutBytes(bs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if sinfo.conn == nil {
|
|
||||||
// There's no connection associated with this session for some reason
|
|
||||||
// TODO: Figure out why this happens sometimes, it shouldn't
|
|
||||||
util.PutBytes(bs)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sinfo._updateNonce(&p.Nonce)
|
sinfo._updateNonce(&p.Nonce)
|
||||||
sinfo.bytesRecvd += uint64(len(bs))
|
sinfo.bytesRecvd += uint64(len(bs))
|
||||||
sinfo.conn.recvMsg(sinfo, bs)
|
sinfo.conn.recvMsg(sinfo, bs)
|
||||||
|
@ -207,11 +207,12 @@ func (t *tcp) listener(l *TcpListener, listenaddr string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Checks if we already are calling this address
|
// Checks if we already are calling this address
|
||||||
func (t *tcp) isAlreadyCalling(saddr string) bool {
|
func (t *tcp) startCalling(saddr string) bool {
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
defer t.mutex.Unlock()
|
defer t.mutex.Unlock()
|
||||||
_, isIn := t.calls[saddr]
|
_, isIn := t.calls[saddr]
|
||||||
return isIn
|
t.calls[saddr] = struct{}{}
|
||||||
|
return !isIn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if a connection already exists.
|
// Checks if a connection already exists.
|
||||||
@ -225,12 +226,9 @@ func (t *tcp) call(saddr string, options interface{}, sintf string) {
|
|||||||
if sintf != "" {
|
if sintf != "" {
|
||||||
callname = fmt.Sprintf("%s/%s", saddr, sintf)
|
callname = fmt.Sprintf("%s/%s", saddr, sintf)
|
||||||
}
|
}
|
||||||
if t.isAlreadyCalling(callname) {
|
if !t.startCalling(callname) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.mutex.Lock()
|
|
||||||
t.calls[callname] = struct{}{}
|
|
||||||
t.mutex.Unlock()
|
|
||||||
defer func() {
|
defer func() {
|
||||||
// Block new calls for a little while, to mitigate livelock scenarios
|
// Block new calls for a little while, to mitigate livelock scenarios
|
||||||
time.Sleep(default_timeout)
|
time.Sleep(default_timeout)
|
||||||
|
Loading…
Reference in New Issue
Block a user