mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-30 07:05:06 +03:00
Tweaks
This commit is contained in:
parent
7b0d315675
commit
326fdd4cf9
2 changed files with 19 additions and 11 deletions
|
@ -235,10 +235,12 @@ func (c *Core) PacketConn() *PacketConn {
|
||||||
// Resolve takes a masked node ID and performs a search, returning the complete
|
// Resolve takes a masked node ID and performs a search, returning the complete
|
||||||
// node ID and the node's public key.
|
// node ID and the node's public key.
|
||||||
func (c *Core) Resolve(nodeID, nodeMask *crypto.NodeID) (fullNodeID *crypto.NodeID, boxPubKey *crypto.BoxPubKey, err error) {
|
func (c *Core) Resolve(nodeID, nodeMask *crypto.NodeID) (fullNodeID *crypto.NodeID, boxPubKey *crypto.BoxPubKey, err error) {
|
||||||
|
fmt.Println("**** START RESOLVE")
|
||||||
|
defer fmt.Println("**** END RESOLVE")
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
c.router.Act(c, func() {
|
c.router.Act(c, func() {
|
||||||
_, isIn := c.router.searches.searches[*nodeID]
|
if _, searching := c.router.searches.searches[*nodeID]; !searching {
|
||||||
if !isIn {
|
|
||||||
searchCompleted := func(sinfo *sessionInfo, e error) {
|
searchCompleted := func(sinfo *sessionInfo, e error) {
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
|
@ -257,8 +259,7 @@ func (c *Core) Resolve(nodeID, nodeMask *crypto.NodeID) (fullNodeID *crypto.Node
|
||||||
close(done)
|
close(done)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sinfo := c.router.searches.newIterSearch(nodeID, nodeMask, searchCompleted)
|
c.router.searches.newIterSearch(nodeID, nodeMask, searchCompleted).startSearch()
|
||||||
sinfo.startSearch()
|
|
||||||
} else {
|
} else {
|
||||||
err = errors.New("search already exists")
|
err = errors.New("search already exists")
|
||||||
close(done)
|
close(done)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package yggdrasil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -73,27 +74,33 @@ func (c *PacketConn) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||||
nodeMask[i] = 0xFF
|
nodeMask[i] = 0xFF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
var session *sessionInfo
|
var session *sessionInfo
|
||||||
phony.Block(c.sessions.router, func() {
|
phony.Block(c.sessions.router, func() {
|
||||||
var ok bool
|
var ok bool
|
||||||
session, ok = c.sessions.getByTheirPerm(boxPubKey)
|
session, ok = c.sessions.getByTheirPerm(boxPubKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
c.sessions.router.core.Resolve(nodeID, nodeMask)
|
nodeID, boxPubKey, err = c.sessions.router.core.Resolve(nodeID, nodeMask)
|
||||||
session, _ = c.sessions.getByTheirPerm(boxPubKey)
|
if err == nil {
|
||||||
|
session, _ = c.sessions.getByTheirPerm(boxPubKey)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("failed to find session/start search: %w", err)
|
||||||
|
}
|
||||||
if session == nil {
|
if session == nil {
|
||||||
return 0, errors.New("expected a session but there was none")
|
return 0, errors.New("expected a session but there was none")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := make(chan error, 1)
|
sendErr := make(chan error, 1)
|
||||||
msg := FlowKeyMessage{Message: b}
|
msg := FlowKeyMessage{Message: b}
|
||||||
|
|
||||||
session.Act(c, func() {
|
session.Act(c, func() {
|
||||||
// Check if the packet is small enough to go through this session
|
// Check if the packet is small enough to go through this session
|
||||||
sessionMTU := session._getMTU()
|
sessionMTU := session._getMTU()
|
||||||
if types.MTU(len(b)) > sessionMTU {
|
if types.MTU(len(b)) > sessionMTU {
|
||||||
err <- PacketConnError{maxsize: int(sessionMTU)}
|
sendErr <- PacketConnError{maxsize: int(sessionMTU)}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,11 +132,11 @@ func (c *PacketConn) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||||
default: // Don't do anything, to keep traffic throttled
|
default: // Don't do anything, to keep traffic throttled
|
||||||
}
|
}
|
||||||
|
|
||||||
err <- nil
|
sendErr <- nil
|
||||||
})
|
})
|
||||||
|
|
||||||
e := <-err
|
err = <-sendErr
|
||||||
return len(b), e
|
return len(b), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements net.PacketConn
|
// implements net.PacketConn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue