Adapt AWDL to link

This commit is contained in:
Neil Alexander 2019-01-23 15:08:19 +00:00
parent 7b2460662d
commit 9c6cf50684
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 51 additions and 54 deletions

View file

@ -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)