mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-30 13:35:19 +00:00
Update awdl.go to use new link stuff (untested)
This commit is contained in:
parent
4ae36dfffe
commit
c51a3340b1
86
src/yggdrasil/awdl.go
Normal file
86
src/yggdrasil/awdl.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package yggdrasil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
type awdl struct {
|
||||||
|
core *Core
|
||||||
|
mutex sync.RWMutex // protects interfaces below
|
||||||
|
interfaces map[string]*awdlInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
type awdlInterface struct {
|
||||||
|
awdl *awdl
|
||||||
|
fromAWDL chan []byte
|
||||||
|
toAWDL chan []byte
|
||||||
|
shutdown chan bool
|
||||||
|
peer *peer
|
||||||
|
link *linkInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *awdl) init(c *Core) error {
|
||||||
|
l.core = c
|
||||||
|
l.mutex.Lock()
|
||||||
|
l.interfaces = make(map[string]*awdlInterface)
|
||||||
|
l.mutex.Unlock()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, name string) (*awdlInterface, error) {
|
||||||
|
link, err := l.core.link.create(fromAWDL, toAWDL, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
intf := awdlInterface{
|
||||||
|
awdl: l,
|
||||||
|
link: link,
|
||||||
|
fromAWDL: fromAWDL,
|
||||||
|
toAWDL: toAWDL,
|
||||||
|
shutdown: make(chan bool),
|
||||||
|
}
|
||||||
|
l.mutex.Lock()
|
||||||
|
l.interfaces[name] = &intf
|
||||||
|
l.mutex.Unlock()
|
||||||
|
return &intf, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *awdl) getInterface(identity string) *awdlInterface {
|
||||||
|
l.mutex.RLock()
|
||||||
|
defer l.mutex.RUnlock()
|
||||||
|
if intf, ok := l.interfaces[identity]; ok {
|
||||||
|
return intf
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *awdl) shutdown(identity string) error {
|
||||||
|
if err := l.core.link.shutdown(identity); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if intf, ok := l.interfaces[identity]; ok {
|
||||||
|
intf.shutdown <- true
|
||||||
|
l.mutex.Lock()
|
||||||
|
delete(l.interfaces, identity)
|
||||||
|
l.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("interface '%s' doesn't exist or already shutdown", identity)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ai *awdlInterface) handler() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ai.shutdown:
|
||||||
|
return
|
||||||
|
case <-ai.link.shutdown:
|
||||||
|
return
|
||||||
|
case in := <-ai.fromAWDL:
|
||||||
|
ai.link.fromlink <- in
|
||||||
|
case out := <-ai.link.tolink:
|
||||||
|
ai.toAWDL <- out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -44,7 +44,8 @@ type Core struct {
|
|||||||
searches searches
|
searches searches
|
||||||
multicast multicast
|
multicast multicast
|
||||||
tcp tcpInterface
|
tcp tcpInterface
|
||||||
link link
|
link link // TODO: not sure if this wants to be here?
|
||||||
|
awdl awdl
|
||||||
log *log.Logger
|
log *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,12 +199,10 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if err := c.awdl.init(c); err != nil {
|
||||||
if err := c.awdl.init(c); err != nil {
|
c.log.Println("Failed to start AWDL interface")
|
||||||
c.log.Println("Failed to start AWDL interface")
|
return err
|
||||||
return err
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if nc.SwitchOptions.MaxTotalQueueSize >= SwitchQueueTotalMinSize {
|
if nc.SwitchOptions.MaxTotalQueueSize >= SwitchQueueTotalMinSize {
|
||||||
c.switchTable.queueTotalMaxSize = nc.SwitchOptions.MaxTotalQueueSize
|
c.switchTable.queueTotalMaxSize = nc.SwitchOptions.MaxTotalQueueSize
|
||||||
|
@ -35,7 +35,7 @@ func (l *link) init(c *Core) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *link) create(fromlink chan []byte, tolink chan []byte /*boxPubKey *crypto.BoxPubKey, sigPubKey *crypto.SigPubKey*/, name string) (*linkInterface, error) {
|
func (l *link) create(fromlink chan []byte, tolink chan []byte, name string) (*linkInterface, error) {
|
||||||
intf := linkInterface{
|
intf := linkInterface{
|
||||||
link: l,
|
link: l,
|
||||||
fromlink: fromlink,
|
fromlink: fromlink,
|
||||||
@ -101,7 +101,7 @@ func (l *link) shutdown(identity string) error {
|
|||||||
l.mutex.Unlock()
|
l.mutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return errors.New(fmt.Sprintf("Interface '%s' doesn't exist or already shutdown", identity))
|
return fmt.Errorf("interface '%s' doesn't exist or already shutdown", identity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user