5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 07:11:40 +00:00

simplify routerInterface

This commit is contained in:
Arceliar 2020-05-23 12:21:01 -05:00
parent 07206b5d46
commit f2b9e95895

View File

@ -62,9 +62,7 @@ func (r *router) init(core *Core) {
}) })
r.peer.Act(r, r.peer._handleIdle) r.peer.Act(r, r.peer._handleIdle)
r.out = func(bs []byte) { r.out = func(bs []byte) {
r.intf.Act(r, func() { r.peer.handlePacketFrom(r, bs)
r.peer.handlePacketFrom(&r.intf, bs)
})
} }
r.nodeinfo.init(r.core) r.nodeinfo.init(r.core)
r.core.config.Mutex.RLock() r.core.config.Mutex.RLock()
@ -262,46 +260,23 @@ func (r *router) _handleNodeInfo(bs []byte, fromKey *crypto.BoxPubKey) {
// routerInterface is a helper that implements peerInterface // routerInterface is a helper that implements peerInterface
type routerInterface struct { type routerInterface struct {
phony.Inbox
router *router router *router
busy bool
} }
func (intf *routerInterface) out(bss [][]byte) { func (intf *routerInterface) out(bss [][]byte) {
intf.Act(intf.router.peer, func() { // Note that this is run in the peer's goroutine
intf.router.Act(intf, func() { intf.router.Act(intf.router.peer, func() {
for _, bs := range bss { for _, bs := range bss {
intf.router._handlePacket(bs) intf.router._handlePacket(bs)
} }
// we may block due to the above
// so we send a message to ourself, that we'd handle after unblocking
// that message tells us to tell the interface that we're finally idle again
intf.router.Act(nil, func() {
intf.Act(intf.router, intf._handleIdle)
}) })
intf.Act(intf.router, intf._handleBusy) //intf.router.peer.Act(nil, intf.router.peer._handleIdle)
}) intf.router.peer._handleIdle()
})
}
func (intf *routerInterface) _handleBusy() {
intf.busy = true
}
func (intf *routerInterface) _handleIdle() {
intf.busy = false
intf.router.peer.Act(intf, intf.router.peer._handleIdle)
} }
func (intf *routerInterface) linkOut(_ []byte) {} func (intf *routerInterface) linkOut(_ []byte) {}
func (intf *routerInterface) notifyQueued(seq uint64) { func (intf *routerInterface) notifyQueued(seq uint64) {}
intf.Act(intf.router.peer, func() {
if intf.busy {
intf.router.peer.dropFromQueue(intf, seq)
}
})
}
func (intf *routerInterface) close() {} func (intf *routerInterface) close() {}