mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-10 15:30:34 +03:00
Try to perform TCP-like key exchange
This commit is contained in:
parent
704e4a062f
commit
f556f3e2a8
@ -34,8 +34,16 @@ func (l *awdl) init(c *Core) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, boxPubKey *crypto.BoxPubKey, sigPubKey *crypto.SigPubKey, name string) (*awdlInterface, error) {
|
||||
/*
|
||||
func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte /*boxPubKey *crypto.BoxPubKey, sigPubKey *crypto.SigPubKey*/, name string) (*awdlInterface, error) {
|
||||
intf := awdlInterface{
|
||||
awdl: l,
|
||||
fromAWDL: fromAWDL,
|
||||
toAWDL: toAWDL,
|
||||
shutdown: make(chan bool),
|
||||
}
|
||||
l.mutex.Lock()
|
||||
l.interfaces[name] = &intf
|
||||
l.mutex.Unlock()
|
||||
myLinkPub, myLinkPriv := crypto.NewBoxKeys()
|
||||
meta := version_getBaseMetadata()
|
||||
meta.box = l.core.boxPub
|
||||
@ -51,25 +59,17 @@ func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, boxPubKey *crypt
|
||||
if !meta.decode(metaBytes) || !meta.check() {
|
||||
return nil, errors.New("Metadata decode failure")
|
||||
}
|
||||
l.core.log.Println("version_getBaseMetadata{}")
|
||||
base := version_getBaseMetadata()
|
||||
if meta.ver > base.ver || meta.ver == base.ver && meta.minorVer > base.minorVer {
|
||||
return nil, errors.New("Failed to connect to node: " + name + " version: " + fmt.Sprintf("%d.%d", meta.ver, meta.minorVer))
|
||||
}
|
||||
l.core.log.Println("crypto.GetSharedKey")
|
||||
shared := crypto.GetSharedKey(myLinkPriv, &meta.link)
|
||||
*/
|
||||
shared := crypto.GetSharedKey(&l.core.boxPriv, boxPubKey)
|
||||
intf := awdlInterface{
|
||||
awdl: l,
|
||||
fromAWDL: fromAWDL,
|
||||
toAWDL: toAWDL,
|
||||
shutdown: make(chan bool),
|
||||
peer: l.core.peers.newPeer(boxPubKey, sigPubKey, shared, name),
|
||||
//peer: l.core.peers.newPeer(&meta.box, &meta.sig, shared, name),
|
||||
}
|
||||
//shared := crypto.GetSharedKey(&l.core.boxPriv, boxPubKey)
|
||||
l.core.log.Println("l.core.peers.newPeer")
|
||||
intf.peer = l.core.peers.newPeer(&meta.box, &meta.sig, shared, name)
|
||||
if intf.peer != nil {
|
||||
l.mutex.Lock()
|
||||
l.interfaces[name] = &intf
|
||||
l.mutex.Unlock()
|
||||
intf.peer.linkOut = make(chan []byte, 1) // protocol traffic
|
||||
intf.peer.out = func(msg []byte) {
|
||||
defer func() { recover() }()
|
||||
@ -84,6 +84,7 @@ func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, boxPubKey *crypt
|
||||
go intf.peer.linkLoop()
|
||||
return &intf, nil
|
||||
}
|
||||
delete(l.interfaces, name)
|
||||
return nil, errors.New("l.core.peers.newPeer failed")
|
||||
}
|
||||
|
||||
|
@ -13,11 +13,9 @@ void Log(const char *text) {
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
||||
)
|
||||
|
||||
@ -31,26 +29,11 @@ func (nsl MobileLogger) Write(p []byte) (n int, err error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (c *Core) AWDLCreateInterface(boxPubKey string, sigPubKey string, name string) error {
|
||||
func (c *Core) AWDLCreateInterface(name string) error {
|
||||
fromAWDL := make(chan []byte, 32)
|
||||
toAWDL := make(chan []byte, 32)
|
||||
|
||||
var boxPub crypto.BoxPubKey
|
||||
var sigPub crypto.SigPubKey
|
||||
boxPubHex, err := hex.DecodeString(boxPubKey)
|
||||
if err != nil {
|
||||
c.log.Println(err)
|
||||
return err
|
||||
}
|
||||
sigPubHex, err := hex.DecodeString(sigPubKey)
|
||||
if err != nil {
|
||||
c.log.Println(err)
|
||||
return err
|
||||
}
|
||||
copy(boxPub[:], boxPubHex)
|
||||
copy(sigPub[:], sigPubHex)
|
||||
|
||||
if intf, err := c.awdl.create(fromAWDL, toAWDL, &boxPub, &sigPub, name); err == nil {
|
||||
if intf, err := c.awdl.create(fromAWDL, toAWDL, name); err == nil {
|
||||
if intf != nil {
|
||||
c.log.Println(err)
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user