mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 22:55:06 +03:00
Adapt AWDL to link
This commit is contained in:
parent
7b2460662d
commit
9c6cf50684
3 changed files with 51 additions and 54 deletions
|
@ -29,22 +29,14 @@ func (nsl MobileLogger) Write(p []byte) (n int, err error) {
|
|||
return len(p), nil
|
||||
}
|
||||
|
||||
func (c *Core) AWDLCreateInterface(name string) error {
|
||||
func (c *Core) AWDLCreateInterface(name, local, remote string) error {
|
||||
fromAWDL := make(chan []byte, 32)
|
||||
toAWDL := make(chan []byte, 32)
|
||||
|
||||
if intf, err := c.awdl.create(fromAWDL, toAWDL, name); err == nil {
|
||||
if intf != nil {
|
||||
c.log.Println(err)
|
||||
return err
|
||||
} else {
|
||||
c.log.Println("c.awdl.create didn't return an interface")
|
||||
return errors.New("c.awdl.create didn't return an interface")
|
||||
}
|
||||
} else {
|
||||
c.log.Println(err)
|
||||
if intf, err := c.awdl.create(fromAWDL, toAWDL, name, local, remote); err != nil || intf == nil {
|
||||
c.log.Println("c.awdl.create:", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) AWDLShutdownInterface(name string) error {
|
||||
|
@ -53,7 +45,7 @@ func (c *Core) AWDLShutdownInterface(name string) error {
|
|||
|
||||
func (c *Core) AWDLRecvPacket(identity string) ([]byte, error) {
|
||||
if intf := c.awdl.getInterface(identity); intf != nil {
|
||||
return <-intf.toAWDL, nil
|
||||
return <-intf.rwc.toAWDL, nil
|
||||
}
|
||||
return nil, errors.New("AWDLRecvPacket identity not known: " + identity)
|
||||
}
|
||||
|
@ -61,7 +53,7 @@ func (c *Core) AWDLRecvPacket(identity string) ([]byte, error) {
|
|||
func (c *Core) AWDLSendPacket(identity string, buf []byte) error {
|
||||
packet := append(util.GetBytes(), buf[:]...)
|
||||
if intf := c.awdl.getInterface(identity); intf != nil {
|
||||
intf.fromAWDL <- packet
|
||||
intf.rwc.fromAWDL <- packet
|
||||
return nil
|
||||
}
|
||||
return errors.New("AWDLSendPacket identity not known: " + identity)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue