mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Initialise awdl.go from link.go, remove deadlock between awdl.create and link.create, other bits and pieces
This commit is contained in:
parent
c51a3340b1
commit
41a410f2a1
4 changed files with 57 additions and 65 deletions
|
@ -18,6 +18,7 @@ type awdlInterface struct {
|
|||
shutdown chan bool
|
||||
peer *peer
|
||||
link *linkInterface
|
||||
stream stream
|
||||
}
|
||||
|
||||
func (l *awdl) init(c *Core) error {
|
||||
|
@ -41,6 +42,8 @@ func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, name string) (*a
|
|||
toAWDL: toAWDL,
|
||||
shutdown: make(chan bool),
|
||||
}
|
||||
intf.stream.init()
|
||||
go intf.handler()
|
||||
l.mutex.Lock()
|
||||
l.interfaces[name] = &intf
|
||||
l.mutex.Unlock()
|
||||
|
@ -71,6 +74,9 @@ func (l *awdl) shutdown(identity string) error {
|
|||
}
|
||||
|
||||
func (ai *awdlInterface) handler() {
|
||||
inPacket := func(packet []byte) {
|
||||
ai.link.fromlink <- packet
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-ai.shutdown:
|
||||
|
@ -78,7 +84,7 @@ func (ai *awdlInterface) handler() {
|
|||
case <-ai.link.shutdown:
|
||||
return
|
||||
case in := <-ai.fromAWDL:
|
||||
ai.link.fromlink <- in
|
||||
ai.stream.write(in, inPacket)
|
||||
case out := <-ai.link.tolink:
|
||||
ai.toAWDL <- out
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue