Listen-Accept-Read-Write pattern now works, amazingly

This commit is contained in:
Neil Alexander 2019-04-19 22:57:52 +01:00
parent 27b78b925d
commit aac88adbed
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 91 additions and 17 deletions

View file

@ -254,6 +254,20 @@ func (c *Core) Stop() {
c.admin.close()
}
// ListenConn returns a listener for Yggdrasil session connections.
func (c *Core) ListenConn() (*Listener, error) {
c.sessions.listenerMutex.Lock()
defer c.sessions.listenerMutex.Unlock()
if c.sessions.listener != nil {
return nil, errors.New("a listener already exists")
}
c.sessions.listener = &Listener{
conn: make(chan *Conn),
close: make(chan interface{}),
}
return c.sessions.listener, nil
}
// 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.