mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-10 07:20:39 +03:00
Access NSLog through Cgo for iOS NetworkExtension logging
This commit is contained in:
parent
6bbd8c1b30
commit
87362a21e2
@ -109,11 +109,12 @@ func (ai *awdlInterface) handler() {
|
||||
timer.Reset(timerInterval)
|
||||
select {
|
||||
case _ = <-timer.C:
|
||||
send([]byte{'H', 'E', 'L', 'L', 'O'})
|
||||
send([]byte{})
|
||||
case p := <-ai.peer.linkOut:
|
||||
send(p)
|
||||
continue
|
||||
case r := <-ai.fromAWDL:
|
||||
//_ = append(util.GetBytes(), r...)
|
||||
ai.peer.handlePacket(r)
|
||||
ai.awdl.core.switchTable.idleIn <- ai.peer.port
|
||||
case <-ai.shutdown:
|
||||
|
@ -24,7 +24,8 @@ import (
|
||||
// therefore we use the "dummy" TUN interface instead.
|
||||
|
||||
func (c *Core) StartAutoconfigure() error {
|
||||
logger := log.New(os.Stdout, "", 0)
|
||||
mobilelog := MobileLogger{}
|
||||
logger := log.New(mobilelog, "", 0)
|
||||
nc := config.GenerateConfig(true)
|
||||
nc.IfName = "dummy"
|
||||
nc.AdminListen = "tcp://localhost:9001"
|
||||
@ -43,7 +44,8 @@ func (c *Core) StartAutoconfigure() error {
|
||||
}
|
||||
|
||||
func (c *Core) StartJSON(configjson []byte) error {
|
||||
logger := log.New(os.Stdout, "", 0)
|
||||
mobilelog := MobileLogger{}
|
||||
logger := log.New(mobilelog, "", 0)
|
||||
nc := config.GenerateConfig(false)
|
||||
var dat map[string]interface{}
|
||||
if err := hjson.Unmarshal(configjson, &dat); err != nil {
|
||||
|
25
src/yggdrasil/mobile_ios.go
Normal file
25
src/yggdrasil/mobile_ios.go
Normal file
@ -0,0 +1,25 @@
|
||||
// +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"
|
||||
import "unsafe"
|
||||
|
||||
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
|
||||
}
|
@ -217,6 +217,7 @@ func (p *peer) handlePacket(packet []byte) {
|
||||
default:
|
||||
util.PutBytes(packet)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Called to handle traffic or protocolTraffic packets.
|
||||
|
Loading…
Reference in New Issue
Block a user