mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-06-16 06:05:06 +03:00
update to ironwood v0.0.0-20230513191034-495699d87ae4 with API changes
This commit is contained in:
parent
1345960d5f
commit
5e95246c26
11 changed files with 235 additions and 198 deletions
|
@ -132,14 +132,14 @@ func (a *AdminSocket) SetupAdminHandlers() {
|
|||
},
|
||||
)
|
||||
_ = a.AddHandler(
|
||||
"getDHT", "Show known DHT entries", []string{},
|
||||
"getTree", "Show known Tree entries", []string{},
|
||||
func(in json.RawMessage) (interface{}, error) {
|
||||
req := &GetDHTRequest{}
|
||||
res := &GetDHTResponse{}
|
||||
req := &GetTreeRequest{}
|
||||
res := &GetTreeResponse{}
|
||||
if err := json.Unmarshal(in, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := a.getDHTHandler(req, res); err != nil {
|
||||
if err := a.getTreeHandler(req, res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package admin
|
||||
|
||||
/*
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"net"
|
||||
|
@ -19,9 +17,10 @@ type GetPathsResponse struct {
|
|||
}
|
||||
|
||||
type PathEntry struct {
|
||||
IPAddress string `json:"address"`
|
||||
PublicKey string `json:"key"`
|
||||
Sequence uint64 `json:"sequence"`
|
||||
IPAddress string `json:"address"`
|
||||
PublicKey string `json:"key"`
|
||||
Path []uint64 `json:"path"`
|
||||
Sequence uint64 `json:"sequence"`
|
||||
}
|
||||
|
||||
func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsResponse) error {
|
||||
|
@ -32,6 +31,7 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons
|
|||
res.Paths = append(res.Paths, PathEntry{
|
||||
IPAddress: net.IP(addr[:]).String(),
|
||||
PublicKey: hex.EncodeToString(p.Key),
|
||||
Path: p.Path,
|
||||
Sequence: p.Sequence,
|
||||
})
|
||||
}
|
||||
|
@ -40,5 +40,3 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons
|
|||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
|
@ -9,13 +9,13 @@ import (
|
|||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||
)
|
||||
|
||||
type GetDHTRequest struct{}
|
||||
type GetTreeRequest struct{}
|
||||
|
||||
type GetDHTResponse struct {
|
||||
DHT []DHTEntry `json:"dht"`
|
||||
type GetTreeResponse struct {
|
||||
Tree []TreeEntry `json:"tree"`
|
||||
}
|
||||
|
||||
type DHTEntry struct {
|
||||
type TreeEntry struct {
|
||||
IPAddress string `json:"address"`
|
||||
PublicKey string `json:"key"`
|
||||
Parent string `json:"parent"`
|
||||
|
@ -24,12 +24,12 @@ type DHTEntry struct {
|
|||
//Rest uint64 `json:"rest"`
|
||||
}
|
||||
|
||||
func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) error {
|
||||
dht := a.core.GetDHT()
|
||||
res.DHT = make([]DHTEntry, 0, len(dht))
|
||||
for _, d := range dht {
|
||||
func (a *AdminSocket) getTreeHandler(req *GetTreeRequest, res *GetTreeResponse) error {
|
||||
tree := a.core.GetTree()
|
||||
res.Tree = make([]TreeEntry, 0, len(tree))
|
||||
for _, d := range tree {
|
||||
addr := address.AddrForKey(d.Key)
|
||||
res.DHT = append(res.DHT, DHTEntry{
|
||||
res.Tree = append(res.Tree, TreeEntry{
|
||||
IPAddress: net.IP(addr[:]).String(),
|
||||
PublicKey: hex.EncodeToString(d.Key[:]),
|
||||
Parent: hex.EncodeToString(d.Parent[:]),
|
||||
|
@ -38,8 +38,8 @@ func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) err
|
|||
//Rest: d.Rest,
|
||||
})
|
||||
}
|
||||
sort.SliceStable(res.DHT, func(i, j int) bool {
|
||||
return strings.Compare(res.DHT[i].PublicKey, res.DHT[j].PublicKey) < 0
|
||||
sort.SliceStable(res.Tree, func(i, j int) bool {
|
||||
return strings.Compare(res.Tree[i].PublicKey, res.Tree[j].PublicKey) < 0
|
||||
})
|
||||
return nil
|
||||
}
|
|
@ -30,7 +30,7 @@ type PeerInfo struct {
|
|||
Uptime time.Duration
|
||||
}
|
||||
|
||||
type DHTEntryInfo struct {
|
||||
type TreeEntryInfo struct {
|
||||
Key ed25519.PublicKey
|
||||
Parent ed25519.PublicKey
|
||||
Sequence uint64
|
||||
|
@ -38,12 +38,11 @@ type DHTEntryInfo struct {
|
|||
//Rest uint64
|
||||
}
|
||||
|
||||
/*
|
||||
type PathEntryInfo struct {
|
||||
Key ed25519.PublicKey
|
||||
Path []uint64
|
||||
Sequence uint64
|
||||
}
|
||||
*/
|
||||
|
||||
type SessionInfo struct {
|
||||
Key ed25519.PublicKey
|
||||
|
@ -94,22 +93,21 @@ func (c *Core) GetPeers() []PeerInfo {
|
|||
return peers
|
||||
}
|
||||
|
||||
func (c *Core) GetDHT() []DHTEntryInfo {
|
||||
var dhts []DHTEntryInfo
|
||||
ds := c.PacketConn.PacketConn.Debug.GetDHT()
|
||||
for _, d := range ds {
|
||||
var info DHTEntryInfo
|
||||
info.Key = d.Key
|
||||
info.Parent = d.Parent
|
||||
info.Sequence = d.Sequence
|
||||
func (c *Core) GetTree() []TreeEntryInfo {
|
||||
var trees []TreeEntryInfo
|
||||
ts := c.PacketConn.PacketConn.Debug.GetTree()
|
||||
for _, t := range ts {
|
||||
var info TreeEntryInfo
|
||||
info.Key = t.Key
|
||||
info.Parent = t.Parent
|
||||
info.Sequence = t.Sequence
|
||||
//info.Port = d.Port
|
||||
//info.Rest = d.Rest
|
||||
dhts = append(dhts, info)
|
||||
trees = append(trees, info)
|
||||
}
|
||||
return dhts
|
||||
return trees
|
||||
}
|
||||
|
||||
/*
|
||||
func (c *Core) GetPaths() []PathEntryInfo {
|
||||
var paths []PathEntryInfo
|
||||
ps := c.PacketConn.PacketConn.Debug.GetPaths()
|
||||
|
@ -117,12 +115,11 @@ func (c *Core) GetPaths() []PathEntryInfo {
|
|||
var info PathEntryInfo
|
||||
info.Key = p.Key
|
||||
info.Sequence = p.Sequence
|
||||
//info.Path = p.Path
|
||||
info.Path = p.Path
|
||||
paths = append(paths, info)
|
||||
}
|
||||
return paths
|
||||
}
|
||||
*/
|
||||
|
||||
func (c *Core) GetSessions() []SessionInfo {
|
||||
var sessions []SessionInfo
|
||||
|
@ -282,8 +279,8 @@ func (c *Core) SetAdmin(a AddHandler) error {
|
|||
return err
|
||||
}
|
||||
if err := a.AddHandler(
|
||||
"debug_remoteGetDHT", "Debug use only", []string{"key"},
|
||||
c.proto.getDHTHandler,
|
||||
"debug_remoteGetTree", "Debug use only", []string{"key"},
|
||||
c.proto.getTreeHandler,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -10,10 +10,12 @@ import (
|
|||
"time"
|
||||
|
||||
iwe "github.com/Arceliar/ironwood/encrypted"
|
||||
iwn "github.com/Arceliar/ironwood/network"
|
||||
iwt "github.com/Arceliar/ironwood/types"
|
||||
"github.com/Arceliar/phony"
|
||||
"github.com/gologme/log"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/version"
|
||||
)
|
||||
|
||||
|
@ -40,6 +42,7 @@ type Core struct {
|
|||
nodeinfoPrivacy NodeInfoPrivacy // immutable after startup
|
||||
_allowedPublicKeys map[[32]byte]struct{} // configurable after startup
|
||||
}
|
||||
pathNotify func(ed25519.PublicKey)
|
||||
}
|
||||
|
||||
func New(secret ed25519.PrivateKey, logger Logger, opts ...SetupOption) (*Core, error) {
|
||||
|
@ -61,7 +64,14 @@ func New(secret ed25519.PrivateKey, logger Logger, opts ...SetupOption) (*Core,
|
|||
copy(c.secret, secret)
|
||||
c.public = secret.Public().(ed25519.PublicKey)
|
||||
var err error
|
||||
if c.PacketConn, err = iwe.NewPacketConn(c.secret); err != nil {
|
||||
keyXform := func(key ed25519.PublicKey) ed25519.PublicKey {
|
||||
return address.SubnetForKey(key).GetKey()
|
||||
}
|
||||
if c.PacketConn, err = iwe.NewPacketConn(c.secret,
|
||||
iwn.WithBloomTransform(keyXform),
|
||||
iwn.WithPeerMaxMessageSize(65535*2),
|
||||
iwn.WithPathNotify(c.doPathNotify),
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("error creating encryption: %w", err)
|
||||
}
|
||||
c.config._peers = map[Peer]*linkInfo{}
|
||||
|
@ -151,11 +161,15 @@ func (c *Core) _close() error {
|
|||
|
||||
func (c *Core) MTU() uint64 {
|
||||
const sessionTypeOverhead = 1
|
||||
return c.PacketConn.MTU() - sessionTypeOverhead
|
||||
MTU := c.PacketConn.MTU() - sessionTypeOverhead
|
||||
if MTU > 65535 {
|
||||
MTU = 65535
|
||||
}
|
||||
return MTU
|
||||
}
|
||||
|
||||
func (c *Core) ReadFrom(p []byte) (n int, from net.Addr, err error) {
|
||||
buf := make([]byte, c.PacketConn.MTU(), 65535)
|
||||
buf := make([]byte, c.PacketConn.MTU())
|
||||
for {
|
||||
bs := buf
|
||||
n, from, err = c.PacketConn.ReadFrom(bs)
|
||||
|
@ -199,6 +213,20 @@ func (c *Core) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (c *Core) doPathNotify(key ed25519.PublicKey) {
|
||||
c.Act(nil, func() {
|
||||
if c.pathNotify != nil {
|
||||
c.pathNotify(key)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Core) SetPathNotify(notify func(ed25519.PublicKey)) {
|
||||
c.Act(nil, func() {
|
||||
c.pathNotify = notify
|
||||
})
|
||||
}
|
||||
|
||||
type Logger interface {
|
||||
Printf(string, ...interface{})
|
||||
Println(...interface{})
|
||||
|
|
|
@ -21,8 +21,8 @@ const (
|
|||
typeDebugGetSelfResponse
|
||||
typeDebugGetPeersRequest
|
||||
typeDebugGetPeersResponse
|
||||
typeDebugGetDHTRequest
|
||||
typeDebugGetDHTResponse
|
||||
typeDebugGetTreeRequest
|
||||
typeDebugGetTreeResponse
|
||||
)
|
||||
|
||||
type reqInfo struct {
|
||||
|
@ -40,7 +40,7 @@ type protoHandler struct {
|
|||
|
||||
selfRequests map[keyArray]*reqInfo
|
||||
peersRequests map[keyArray]*reqInfo
|
||||
dhtRequests map[keyArray]*reqInfo
|
||||
treeRequests map[keyArray]*reqInfo
|
||||
}
|
||||
|
||||
func (p *protoHandler) init(core *Core) {
|
||||
|
@ -49,7 +49,7 @@ func (p *protoHandler) init(core *Core) {
|
|||
|
||||
p.selfRequests = make(map[keyArray]*reqInfo)
|
||||
p.peersRequests = make(map[keyArray]*reqInfo)
|
||||
p.dhtRequests = make(map[keyArray]*reqInfo)
|
||||
p.treeRequests = make(map[keyArray]*reqInfo)
|
||||
}
|
||||
|
||||
// Common functions
|
||||
|
@ -89,10 +89,10 @@ func (p *protoHandler) _handleDebug(key keyArray, bs []byte) {
|
|||
p._handleGetPeersRequest(key)
|
||||
case typeDebugGetPeersResponse:
|
||||
p._handleGetPeersResponse(key, bs[1:])
|
||||
case typeDebugGetDHTRequest:
|
||||
p._handleGetDHTRequest(key)
|
||||
case typeDebugGetDHTResponse:
|
||||
p._handleGetDHTResponse(key, bs[1:])
|
||||
case typeDebugGetTreeRequest:
|
||||
p._handleGetTreeRequest(key)
|
||||
case typeDebugGetTreeResponse:
|
||||
p._handleGetTreeResponse(key, bs[1:])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,47 +188,47 @@ func (p *protoHandler) _handleGetPeersResponse(key keyArray, bs []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
// Get DHT
|
||||
// Get Tree
|
||||
|
||||
func (p *protoHandler) sendGetDHTRequest(key keyArray, callback func([]byte)) {
|
||||
func (p *protoHandler) sendGetTreeRequest(key keyArray, callback func([]byte)) {
|
||||
p.Act(nil, func() {
|
||||
if info := p.dhtRequests[key]; info != nil {
|
||||
if info := p.treeRequests[key]; info != nil {
|
||||
info.timer.Stop()
|
||||
delete(p.dhtRequests, key)
|
||||
delete(p.treeRequests, key)
|
||||
}
|
||||
info := new(reqInfo)
|
||||
info.callback = callback
|
||||
info.timer = time.AfterFunc(time.Minute, func() {
|
||||
p.Act(nil, func() {
|
||||
if p.dhtRequests[key] == info {
|
||||
delete(p.dhtRequests, key)
|
||||
if p.treeRequests[key] == info {
|
||||
delete(p.treeRequests, key)
|
||||
}
|
||||
})
|
||||
})
|
||||
p.dhtRequests[key] = info
|
||||
p._sendDebug(key, typeDebugGetDHTRequest, nil)
|
||||
p.treeRequests[key] = info
|
||||
p._sendDebug(key, typeDebugGetTreeRequest, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func (p *protoHandler) _handleGetDHTRequest(key keyArray) {
|
||||
dinfos := p.core.GetDHT()
|
||||
func (p *protoHandler) _handleGetTreeRequest(key keyArray) {
|
||||
dinfos := p.core.GetTree()
|
||||
var bs []byte
|
||||
for _, dinfo := range dinfos {
|
||||
tmp := append(bs, dinfo.Key[:]...)
|
||||
const responseOverhead = 2 // 1 debug type, 1 getdht type
|
||||
const responseOverhead = 2 // 1 debug type, 1 gettree type
|
||||
if uint64(len(tmp))+responseOverhead > p.core.MTU() {
|
||||
break
|
||||
}
|
||||
bs = tmp
|
||||
}
|
||||
p._sendDebug(key, typeDebugGetDHTResponse, bs)
|
||||
p._sendDebug(key, typeDebugGetTreeResponse, bs)
|
||||
}
|
||||
|
||||
func (p *protoHandler) _handleGetDHTResponse(key keyArray, bs []byte) {
|
||||
if info := p.dhtRequests[key]; info != nil {
|
||||
func (p *protoHandler) _handleGetTreeResponse(key keyArray, bs []byte) {
|
||||
if info := p.treeRequests[key]; info != nil {
|
||||
info.timer.Stop()
|
||||
info.callback(bs)
|
||||
delete(p.dhtRequests, key)
|
||||
delete(p.treeRequests, key)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,16 +322,16 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error)
|
|||
}
|
||||
}
|
||||
|
||||
// Admin socket stuff for "Get DHT"
|
||||
// Admin socket stuff for "Get Tree"
|
||||
|
||||
type DebugGetDHTRequest struct {
|
||||
type DebugGetTreeRequest struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type DebugGetDHTResponse map[string]interface{}
|
||||
type DebugGetTreeResponse map[string]interface{}
|
||||
|
||||
func (p *protoHandler) getDHTHandler(in json.RawMessage) (interface{}, error) {
|
||||
var req DebugGetDHTRequest
|
||||
func (p *protoHandler) getTreeHandler(in json.RawMessage) (interface{}, error) {
|
||||
var req DebugGetTreeRequest
|
||||
if err := json.Unmarshal(in, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ func (p *protoHandler) getDHTHandler(in json.RawMessage) (interface{}, error) {
|
|||
}
|
||||
copy(key[:], kbs)
|
||||
ch := make(chan []byte, 1)
|
||||
p.sendGetDHTRequest(key, func(info []byte) {
|
||||
p.sendGetTreeRequest(key, func(info []byte) {
|
||||
ch <- info
|
||||
})
|
||||
timer := time.NewTimer(6 * time.Second)
|
||||
|
@ -367,7 +367,7 @@ func (p *protoHandler) getDHTHandler(in json.RawMessage) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
ip := net.IP(address.AddrForKey(kbs)[:])
|
||||
res := DebugGetDHTResponse{ip.String(): msg}
|
||||
res := DebugGetTreeResponse{ip.String(): msg}
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,16 +31,16 @@ const (
|
|||
type keyArray [ed25519.PublicKeySize]byte
|
||||
|
||||
type keyStore struct {
|
||||
core *core.Core
|
||||
address address.Address
|
||||
subnet address.Subnet
|
||||
mutex sync.Mutex
|
||||
keyToInfo map[keyArray]*keyInfo
|
||||
addrToInfo map[address.Address]*keyInfo
|
||||
//addrBuffer map[address.Address]*buffer
|
||||
core *core.Core
|
||||
address address.Address
|
||||
subnet address.Subnet
|
||||
mutex sync.Mutex
|
||||
keyToInfo map[keyArray]*keyInfo
|
||||
addrToInfo map[address.Address]*keyInfo
|
||||
addrBuffer map[address.Address]*buffer
|
||||
subnetToInfo map[address.Subnet]*keyInfo
|
||||
//subnetBuffer map[address.Subnet]*buffer
|
||||
mtu uint64
|
||||
subnetBuffer map[address.Subnet]*buffer
|
||||
mtu uint64
|
||||
}
|
||||
|
||||
type keyInfo struct {
|
||||
|
@ -50,12 +50,10 @@ type keyInfo struct {
|
|||
timeout *time.Timer // From calling a time.AfterFunc to do cleanup
|
||||
}
|
||||
|
||||
/*
|
||||
type buffer struct {
|
||||
packet []byte
|
||||
timeout *time.Timer
|
||||
}
|
||||
*/
|
||||
|
||||
func (k *keyStore) init(c *core.Core) {
|
||||
k.core = c
|
||||
|
@ -65,11 +63,14 @@ func (k *keyStore) init(c *core.Core) {
|
|||
err = fmt.Errorf("tun.core.SetOutOfBandHander: %w", err)
|
||||
panic(err)
|
||||
}*/
|
||||
k.core.SetPathNotify(func(key ed25519.PublicKey) {
|
||||
k.update(key)
|
||||
})
|
||||
k.keyToInfo = make(map[keyArray]*keyInfo)
|
||||
k.addrToInfo = make(map[address.Address]*keyInfo)
|
||||
//k.addrBuffer = make(map[address.Address]*buffer)
|
||||
k.addrBuffer = make(map[address.Address]*buffer)
|
||||
k.subnetToInfo = make(map[address.Subnet]*keyInfo)
|
||||
//k.subnetBuffer = make(map[address.Subnet]*buffer)
|
||||
k.subnetBuffer = make(map[address.Subnet]*buffer)
|
||||
k.mtu = 1280 // Default to something safe, expect user to set this
|
||||
}
|
||||
|
||||
|
@ -80,33 +81,25 @@ func (k *keyStore) sendToAddress(addr address.Address, bs []byte) {
|
|||
k.mutex.Unlock()
|
||||
_, _ = k.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
||||
} else {
|
||||
/*
|
||||
var buf *buffer
|
||||
if buf = k.addrBuffer[addr]; buf == nil {
|
||||
buf = new(buffer)
|
||||
k.addrBuffer[addr] = buf
|
||||
}
|
||||
msg := append([]byte(nil), bs...)
|
||||
buf.packet = msg
|
||||
if buf.timeout != nil {
|
||||
buf.timeout.Stop()
|
||||
}
|
||||
buf.timeout = time.AfterFunc(keyStoreTimeout, func() {
|
||||
k.mutex.Lock()
|
||||
defer k.mutex.Unlock()
|
||||
if nbuf := k.addrBuffer[addr]; nbuf == buf {
|
||||
delete(k.addrBuffer, addr)
|
||||
}
|
||||
})
|
||||
k.mutex.Unlock()
|
||||
k.sendKeyLookup(addr.GetKey())
|
||||
*/
|
||||
k.mutex.Unlock()
|
||||
key := k.core.GetKeyFor(addr.GetKey())
|
||||
info := k.update(key)
|
||||
if info.address == addr {
|
||||
_, _ = k.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
||||
var buf *buffer
|
||||
if buf = k.addrBuffer[addr]; buf == nil {
|
||||
buf = new(buffer)
|
||||
k.addrBuffer[addr] = buf
|
||||
}
|
||||
msg := append([]byte(nil), bs...)
|
||||
buf.packet = msg
|
||||
if buf.timeout != nil {
|
||||
buf.timeout.Stop()
|
||||
}
|
||||
buf.timeout = time.AfterFunc(keyStoreTimeout, func() {
|
||||
k.mutex.Lock()
|
||||
defer k.mutex.Unlock()
|
||||
if nbuf := k.addrBuffer[addr]; nbuf == buf {
|
||||
delete(k.addrBuffer, addr)
|
||||
}
|
||||
})
|
||||
k.mutex.Unlock()
|
||||
k.sendKeyLookup(addr.GetKey())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,33 +110,25 @@ func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) {
|
|||
k.mutex.Unlock()
|
||||
_, _ = k.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
||||
} else {
|
||||
/*
|
||||
var buf *buffer
|
||||
if buf = k.subnetBuffer[subnet]; buf == nil {
|
||||
buf = new(buffer)
|
||||
k.subnetBuffer[subnet] = buf
|
||||
}
|
||||
msg := append([]byte(nil), bs...)
|
||||
buf.packet = msg
|
||||
if buf.timeout != nil {
|
||||
buf.timeout.Stop()
|
||||
}
|
||||
buf.timeout = time.AfterFunc(keyStoreTimeout, func() {
|
||||
k.mutex.Lock()
|
||||
defer k.mutex.Unlock()
|
||||
if nbuf := k.subnetBuffer[subnet]; nbuf == buf {
|
||||
delete(k.subnetBuffer, subnet)
|
||||
}
|
||||
})
|
||||
k.mutex.Unlock()
|
||||
k.sendKeyLookup(subnet.GetKey())
|
||||
*/
|
||||
k.mutex.Unlock()
|
||||
key := k.core.GetKeyFor(subnet.GetKey())
|
||||
info := k.update(key)
|
||||
if info.subnet == subnet {
|
||||
_, _ = k.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
||||
var buf *buffer
|
||||
if buf = k.subnetBuffer[subnet]; buf == nil {
|
||||
buf = new(buffer)
|
||||
k.subnetBuffer[subnet] = buf
|
||||
}
|
||||
msg := append([]byte(nil), bs...)
|
||||
buf.packet = msg
|
||||
if buf.timeout != nil {
|
||||
buf.timeout.Stop()
|
||||
}
|
||||
buf.timeout = time.AfterFunc(keyStoreTimeout, func() {
|
||||
k.mutex.Lock()
|
||||
defer k.mutex.Unlock()
|
||||
if nbuf := k.subnetBuffer[subnet]; nbuf == buf {
|
||||
delete(k.subnetBuffer, subnet)
|
||||
}
|
||||
})
|
||||
k.mutex.Unlock()
|
||||
k.sendKeyLookup(subnet.GetKey())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,16 +146,14 @@ func (k *keyStore) update(key ed25519.PublicKey) *keyInfo {
|
|||
k.keyToInfo[info.key] = info
|
||||
k.addrToInfo[info.address] = info
|
||||
k.subnetToInfo[info.subnet] = info
|
||||
/*
|
||||
if buf := k.addrBuffer[info.address]; buf != nil {
|
||||
packets = append(packets, buf.packet)
|
||||
delete(k.addrBuffer, info.address)
|
||||
}
|
||||
if buf := k.subnetBuffer[info.subnet]; buf != nil {
|
||||
packets = append(packets, buf.packet)
|
||||
delete(k.subnetBuffer, info.subnet)
|
||||
}
|
||||
*/
|
||||
if buf := k.addrBuffer[info.address]; buf != nil {
|
||||
packets = append(packets, buf.packet)
|
||||
delete(k.addrBuffer, info.address)
|
||||
}
|
||||
if buf := k.subnetBuffer[info.subnet]; buf != nil {
|
||||
packets = append(packets, buf.packet)
|
||||
delete(k.subnetBuffer, info.subnet)
|
||||
}
|
||||
}
|
||||
k.resetTimeout(info)
|
||||
k.mutex.Unlock()
|
||||
|
@ -223,14 +206,17 @@ func (k *keyStore) oobHandler(fromKey, toKey ed25519.PublicKey, data []byte) { /
|
|||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
func (k *keyStore) sendKeyLookup(partial ed25519.PublicKey) {
|
||||
sig := ed25519.Sign(k.core.PrivateKey(), partial[:])
|
||||
bs := append([]byte{typeKeyLookup}, sig...)
|
||||
//_ = k.core.SendOutOfBand(partial, bs)
|
||||
_ = bs
|
||||
/*
|
||||
sig := ed25519.Sign(k.core.PrivateKey(), partial[:])
|
||||
bs := append([]byte{typeKeyLookup}, sig...)
|
||||
//_ = k.core.SendOutOfBand(partial, bs)
|
||||
_ = bs
|
||||
*/
|
||||
k.core.SendLookup(partial)
|
||||
}
|
||||
|
||||
/*
|
||||
func (k *keyStore) sendKeyResponse(dest ed25519.PublicKey) { // nolint:unused
|
||||
sig := ed25519.Sign(k.core.PrivateKey(), dest[:])
|
||||
bs := append([]byte{typeKeyResponse}, sig...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue