Move some things around a bit, delete session workers

This commit is contained in:
Neil Alexander 2019-04-19 00:11:43 +01:00
parent b2f4f2e1b6
commit b20c8b6da5
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 32 additions and 159 deletions

View file

@ -254,6 +254,38 @@ func (c *Core) Stop() {
c.admin.close()
}
// Dial opens a session to the given node. The first paramter should be "nodeid"
// and the second parameter should contain a hexadecimal representation of the
// target node ID.
func (c *Core) Dial(network, address string) (Conn, error) {
conn := Conn{}
nodeID := crypto.NodeID{}
nodeMask := crypto.NodeID{}
// Process
switch network {
case "nodeid":
// A node ID was provided - we don't need to do anything special with it
dest, err := hex.DecodeString(address)
if err != nil {
return Conn{}, err
}
copy(nodeID[:], dest)
for i := range nodeMask {
nodeMask[i] = 0xFF
}
default:
// An unexpected address type was given, so give up
return Conn{}, errors.New("unexpected address type")
}
conn.core = c
conn.nodeID = &nodeID
conn.nodeMask = &nodeMask
conn.core.router.doAdmin(func() {
conn.startSearch()
})
return conn, nil
}
// ListenTCP starts a new TCP listener. The input URI should match that of the
// "Listen" configuration item, e.g.
// tcp://a.b.c.d:e