mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 18:51:38 +00:00
Remove router.doAdmin and switchTable.doAdmin
This commit is contained in:
parent
a8b323acdd
commit
5d7d84f827
@ -56,8 +56,7 @@ func (c *cryptokey) init(tun *TunAdapter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the CKR routes - this must only ever be called from the router
|
// Configure the CKR routes.
|
||||||
// goroutine, e.g. through router.doAdmin
|
|
||||||
func (c *cryptokey) configure() error {
|
func (c *cryptokey) configure() error {
|
||||||
current := c.tun.config.GetCurrent()
|
current := c.tun.config.GetCurrent()
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ func (c *Core) GetDHT() []DHTEntry {
|
|||||||
dhtentries = append(dhtentries, info)
|
dhtentries = append(dhtentries, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.router.doAdmin(getDHT)
|
phony.Block(c.router, getDHT)
|
||||||
return dhtentries
|
return dhtentries
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +205,8 @@ func (c *Core) GetSwitchQueues() SwitchQueues {
|
|||||||
}
|
}
|
||||||
switchqueues.Queues = append(switchqueues.Queues, queue)
|
switchqueues.Queues = append(switchqueues.Queues, queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
c.switchTable.doAdmin(getSwitchQueues)
|
phony.Block(c.switchTable, getSwitchQueues)
|
||||||
return switchqueues
|
return switchqueues
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +243,7 @@ func (c *Core) GetSessions() []Session {
|
|||||||
sessions = append(sessions, session)
|
sessions = append(sessions, session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.router.doAdmin(getSessions)
|
phony.Block(c.router, getSessions)
|
||||||
return sessions
|
return sessions
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +344,7 @@ func (c *Core) GetNodeInfo(key crypto.BoxPubKey, coords []uint64, nocache bool)
|
|||||||
})
|
})
|
||||||
c.router.nodeinfo.sendNodeInfo(key, wire_coordsUint64stoBytes(coords), false)
|
c.router.nodeinfo.sendNodeInfo(key, wire_coordsUint64stoBytes(coords), false)
|
||||||
}
|
}
|
||||||
c.router.doAdmin(sendNodeInfoRequest)
|
phony.Block(c.router, sendNodeInfoRequest)
|
||||||
timer := time.AfterFunc(6*time.Second, func() { close(response) })
|
timer := time.AfterFunc(6*time.Second, func() { close(response) })
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
for res := range response {
|
for res := range response {
|
||||||
@ -455,7 +454,7 @@ func (c *Core) DHTPing(key crypto.BoxPubKey, coords []uint64, target *crypto.Nod
|
|||||||
})
|
})
|
||||||
c.router.dht.ping(&info, &rq.dest)
|
c.router.dht.ping(&info, &rq.dest)
|
||||||
}
|
}
|
||||||
c.router.doAdmin(sendPing)
|
phony.Block(c.router, sendPing)
|
||||||
// TODO: do something better than the below...
|
// TODO: do something better than the below...
|
||||||
res := <-resCh
|
res := <-resCh
|
||||||
if res != nil {
|
if res != nil {
|
||||||
|
@ -92,7 +92,9 @@ func (c *Conn) setMTU(from phony.Actor, mtu uint16) {
|
|||||||
func (c *Conn) search() error {
|
func (c *Conn) search() error {
|
||||||
var sinfo *searchInfo
|
var sinfo *searchInfo
|
||||||
var isIn bool
|
var isIn bool
|
||||||
c.core.router.doAdmin(func() { sinfo, isIn = c.core.router.searches.searches[*c.nodeID] })
|
phony.Block(c.core.router, func() {
|
||||||
|
sinfo, isIn = c.core.router.searches.searches[*c.nodeID]
|
||||||
|
})
|
||||||
if !isIn {
|
if !isIn {
|
||||||
done := make(chan struct{}, 1)
|
done := make(chan struct{}, 1)
|
||||||
var sess *sessionInfo
|
var sess *sessionInfo
|
||||||
@ -106,7 +108,7 @@ func (c *Conn) search() error {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.core.router.doAdmin(func() {
|
phony.Block(c.core.router, func() {
|
||||||
sinfo = c.core.router.searches.newIterSearch(c.nodeID, c.nodeMask, searchCompleted)
|
sinfo = c.core.router.searches.newIterSearch(c.nodeID, c.nodeMask, searchCompleted)
|
||||||
sinfo.continueSearch()
|
sinfo.continueSearch()
|
||||||
})
|
})
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Arceliar/phony"
|
||||||
"github.com/gologme/log"
|
"github.com/gologme/log"
|
||||||
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||||
@ -175,7 +176,7 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) (*config.NodeState,
|
|||||||
|
|
||||||
c.config.Mutex.RLock()
|
c.config.Mutex.RLock()
|
||||||
if c.config.Current.SwitchOptions.MaxTotalQueueSize >= SwitchQueueTotalMinSize {
|
if c.config.Current.SwitchOptions.MaxTotalQueueSize >= SwitchQueueTotalMinSize {
|
||||||
c.switchTable.doAdmin(func() {
|
phony.Block(c.switchTable, func() {
|
||||||
c.switchTable.queues.totalMaxSize = c.config.Current.SwitchOptions.MaxTotalQueueSize
|
c.switchTable.queues.totalMaxSize = c.config.Current.SwitchOptions.MaxTotalQueueSize
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ func DEBUG_wire_encode_coords(coords []byte) []byte {
|
|||||||
|
|
||||||
func (c *Core) DEBUG_getDHTSize() int {
|
func (c *Core) DEBUG_getDHTSize() int {
|
||||||
var total int
|
var total int
|
||||||
c.router.doAdmin(func() {
|
phony.Block(c.router, func() {
|
||||||
total = len(c.router.dht.table)
|
total = len(c.router.dht.table)
|
||||||
})
|
})
|
||||||
return total
|
return total
|
||||||
|
@ -149,7 +149,7 @@ func (ps *peers) removePeer(port switchPort) {
|
|||||||
if port == 0 {
|
if port == 0 {
|
||||||
return
|
return
|
||||||
} // Can't remove self peer
|
} // Can't remove self peer
|
||||||
ps.core.router.doAdmin(func() {
|
phony.Block(ps.core.router, func() {
|
||||||
ps.core.switchTable.forgetPeer(port)
|
ps.core.switchTable.forgetPeer(port)
|
||||||
})
|
})
|
||||||
ps.mutex.Lock()
|
ps.mutex.Lock()
|
||||||
|
@ -251,8 +251,3 @@ func (r *router) _handleNodeInfo(bs []byte, fromKey *crypto.BoxPubKey) {
|
|||||||
req.SendPermPub = *fromKey
|
req.SendPermPub = *fromKey
|
||||||
r.nodeinfo.handleNodeInfo(&req)
|
r.nodeinfo.handleNodeInfo(&req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove this, have things either be actors that send message or else call Block directly
|
|
||||||
func (r *router) doAdmin(f func()) {
|
|
||||||
phony.Block(r, f)
|
|
||||||
}
|
|
||||||
|
@ -278,7 +278,7 @@ func (t *switchTable) blockPeer(port switchPort) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Removes a peer.
|
// Removes a peer.
|
||||||
// Must be called by the router mainLoop goroutine, e.g. call router.doAdmin with a lambda that calls this.
|
// Must be called by the router actor with a lambda that calls this.
|
||||||
// If the removed peer was this node's parent, it immediately tries to find a new parent.
|
// If the removed peer was this node's parent, it immediately tries to find a new parent.
|
||||||
func (t *switchTable) forgetPeer(port switchPort) {
|
func (t *switchTable) forgetPeer(port switchPort) {
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
@ -866,9 +866,3 @@ func (t *switchTable) _idleIn(port switchPort) {
|
|||||||
t.idle[port] = time.Now()
|
t.idle[port] = time.Now()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passed a function to call.
|
|
||||||
// This will send the function to t.admin and block until it finishes.
|
|
||||||
func (t *switchTable) doAdmin(f func()) {
|
|
||||||
phony.Block(t, f)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user