Add missing path notify and bloom transform

This commit is contained in:
Neil Alexander 2023-05-19 19:33:40 +01:00
parent a9ec3877b5
commit 7b1635245f
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -13,10 +13,12 @@ import (
"time" "time"
iwe "github.com/Arceliar/ironwood/encrypted" iwe "github.com/Arceliar/ironwood/encrypted"
iwn "github.com/Arceliar/ironwood/network"
iwt "github.com/Arceliar/ironwood/types" iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony" "github.com/Arceliar/phony"
"github.com/gologme/log" "github.com/gologme/log"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/version" "github.com/yggdrasil-network/yggdrasil-go/src/version"
) )
@ -93,7 +95,15 @@ func New(cert *tls.Certificate, logger Logger, opts ...SetupOption) (*Core, erro
if c.config.tls, err = c.generateTLSConfig(cert); err != nil { if c.config.tls, err = c.generateTLSConfig(cert); err != nil {
return nil, fmt.Errorf("error generating TLS config: %w", err) return nil, fmt.Errorf("error generating TLS config: %w", err)
} }
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) return nil, fmt.Errorf("error creating encryption: %w", err)
} }
address, subnet := c.Address(), c.Subnet() address, subnet := c.Address(), c.Subnet()
@ -217,6 +227,14 @@ func (c *Core) WriteTo(p []byte, addr net.Addr) (n int, err error) {
return 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)) { func (c *Core) SetPathNotify(notify func(ed25519.PublicKey)) {
c.Act(nil, func() { c.Act(nil, func() {
c.pathNotify = notify c.pathNotify = notify