mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
Comment out AWDL (doesn't work in iOS properly) and move out of main package
This commit is contained in:
parent
350b51cabb
commit
90feae6a7d
1 changed files with 3 additions and 1 deletions
108
src/mobile/awdl.go
Normal file
108
src/mobile/awdl.go
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type awdl struct {
|
||||
link *link
|
||||
reconfigure chan chan error
|
||||
mutex sync.RWMutex // protects interfaces below
|
||||
interfaces map[string]*awdlInterface
|
||||
}
|
||||
|
||||
type awdlInterface struct {
|
||||
linkif *linkInterface
|
||||
rwc awdlReadWriteCloser
|
||||
peer *peer
|
||||
stream stream
|
||||
}
|
||||
|
||||
type awdlReadWriteCloser struct {
|
||||
fromAWDL chan []byte
|
||||
toAWDL chan []byte
|
||||
}
|
||||
|
||||
func (c awdlReadWriteCloser) Read(p []byte) (n int, err error) {
|
||||
if packet, ok := <-c.fromAWDL; ok {
|
||||
n = copy(p, packet)
|
||||
return n, nil
|
||||
}
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func (c awdlReadWriteCloser) Write(p []byte) (n int, err error) {
|
||||
var pc []byte
|
||||
pc = append(pc, p...)
|
||||
c.toAWDL <- pc
|
||||
return len(pc), nil
|
||||
}
|
||||
|
||||
func (c awdlReadWriteCloser) Close() error {
|
||||
close(c.fromAWDL)
|
||||
close(c.toAWDL)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *awdl) init(l *link) error {
|
||||
a.link = l
|
||||
a.mutex.Lock()
|
||||
a.interfaces = make(map[string]*awdlInterface)
|
||||
a.reconfigure = make(chan chan error, 1)
|
||||
a.mutex.Unlock()
|
||||
|
||||
go func() {
|
||||
for e := range a.reconfigure {
|
||||
e <- nil
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *awdl) create(name, local, remote string, incoming bool) (*awdlInterface, error) {
|
||||
rwc := awdlReadWriteCloser{
|
||||
fromAWDL: make(chan []byte, 1),
|
||||
toAWDL: make(chan []byte, 1),
|
||||
}
|
||||
s := stream{}
|
||||
s.init(rwc)
|
||||
linkif, err := a.link.create(&s, name, "awdl", local, remote, incoming, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
intf := awdlInterface{
|
||||
linkif: linkif,
|
||||
rwc: rwc,
|
||||
}
|
||||
a.mutex.Lock()
|
||||
a.interfaces[name] = &intf
|
||||
a.mutex.Unlock()
|
||||
go intf.linkif.handler()
|
||||
return &intf, nil
|
||||
}
|
||||
|
||||
func (a *awdl) getInterface(identity string) *awdlInterface {
|
||||
a.mutex.RLock()
|
||||
defer a.mutex.RUnlock()
|
||||
if intf, ok := a.interfaces[identity]; ok {
|
||||
return intf
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *awdl) shutdown(identity string) error {
|
||||
if intf, ok := a.interfaces[identity]; ok {
|
||||
close(intf.linkif.closed)
|
||||
intf.rwc.Close()
|
||||
a.mutex.Lock()
|
||||
delete(a.interfaces, identity)
|
||||
a.mutex.Unlock()
|
||||
return nil
|
||||
}
|
||||
return errors.New("Interface not found or already closed")
|
||||
}
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue