2019-01-05 21:59:07 +00:00
|
|
|
// +build mobile,darwin
|
|
|
|
|
|
|
|
package yggdrasil
|
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -x objective-c
|
|
|
|
#cgo LDFLAGS: -framework Foundation
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
void Log(const char *text) {
|
|
|
|
NSString *nss = [NSString stringWithUTF8String:text];
|
|
|
|
NSLog(@"%@", nss);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
import "C"
|
2019-01-10 11:31:04 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
|
|
|
)
|
2019-01-05 21:59:07 +00:00
|
|
|
|
|
|
|
type MobileLogger struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nsl MobileLogger) Write(p []byte) (n int, err error) {
|
|
|
|
p = append(p, 0)
|
|
|
|
cstr := (*C.char)(unsafe.Pointer(&p[0]))
|
|
|
|
C.Log(cstr)
|
|
|
|
return len(p), nil
|
|
|
|
}
|
2019-01-10 11:31:04 +00:00
|
|
|
|
2019-02-01 00:02:17 +00:00
|
|
|
func (c *Core) AWDLCreateInterface(name, local, remote string, incoming bool) error {
|
|
|
|
if intf, err := c.link.awdl.create(name, local, remote, incoming); err != nil || intf == nil {
|
2019-01-23 19:42:33 +00:00
|
|
|
c.log.Println("c.link.awdl.create:", err)
|
2019-01-10 11:31:04 +00:00
|
|
|
return err
|
|
|
|
}
|
2019-01-23 15:08:19 +00:00
|
|
|
return nil
|
2019-01-10 11:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) AWDLShutdownInterface(name string) error {
|
2019-01-23 19:42:33 +00:00
|
|
|
return c.link.awdl.shutdown(name)
|
2019-01-10 11:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) AWDLRecvPacket(identity string) ([]byte, error) {
|
2019-01-23 19:42:33 +00:00
|
|
|
if intf := c.link.awdl.getInterface(identity); intf != nil {
|
2019-01-23 17:05:16 +00:00
|
|
|
read, ok := <-intf.rwc.toAWDL
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("AWDLRecvPacket: channel closed")
|
|
|
|
}
|
|
|
|
return read, nil
|
2019-01-10 11:31:04 +00:00
|
|
|
}
|
|
|
|
return nil, errors.New("AWDLRecvPacket identity not known: " + identity)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) AWDLSendPacket(identity string, buf []byte) error {
|
|
|
|
packet := append(util.GetBytes(), buf[:]...)
|
2019-01-23 19:42:33 +00:00
|
|
|
if intf := c.link.awdl.getInterface(identity); intf != nil {
|
2019-01-23 15:08:19 +00:00
|
|
|
intf.rwc.fromAWDL <- packet
|
2019-01-10 11:31:04 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return errors.New("AWDLSendPacket identity not known: " + identity)
|
|
|
|
}
|