sends out introduction to peers
This commit is contained in:
@@ -21,13 +21,11 @@ var (
|
||||
)
|
||||
|
||||
// Len is the length of the signatures used in Indra, compact keys that can have
|
||||
// the public key extracted from them, thus eliminating the need to separately
|
||||
// specify it in messages.
|
||||
// the public key extracted from them.
|
||||
const Len = 65
|
||||
|
||||
// Bytes is an ECDSA BIP62 formatted compact signature which allows the recovery
|
||||
// of the public key from the signature. This allows messages to avoid adding
|
||||
// extra bytes to also specify the public key of the signer.
|
||||
// of the public key from the signature.
|
||||
type Bytes [Len]byte
|
||||
|
||||
// Sign produces an ECDSA BIP62 compact signature.
|
||||
|
||||
@@ -65,9 +65,9 @@ func (x *Layer) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
|
||||
}
|
||||
splice.Splice(b, c).
|
||||
ReadID(&x.ID).
|
||||
ReadPubkey(&x.Key).
|
||||
ReadAddrPort(&x.AddrPort).
|
||||
ReadSignature(x.Bytes).
|
||||
ReadPubkey(&x.Layer.Key).
|
||||
ReadAddrPort(&x.Layer.AddrPort).
|
||||
ReadSignature(&x.Layer.Bytes).
|
||||
ReadHash(&x.Ciphers[0]).ReadHash(&x.Ciphers[1]).ReadHash(&x.Ciphers[2]).
|
||||
ReadIV(&x.Nonces[0]).ReadIV(&x.Nonces[1]).ReadIV(&x.Nonces[2])
|
||||
return
|
||||
|
||||
@@ -32,12 +32,12 @@ var (
|
||||
)
|
||||
|
||||
type Layer struct {
|
||||
*pub.Key
|
||||
*netip.AddrPort
|
||||
sig.Bytes
|
||||
Key *pub.Key
|
||||
AddrPort *netip.AddrPort
|
||||
Bytes sig.Bytes
|
||||
}
|
||||
|
||||
func New(key *prv.Key, ap *netip.AddrPort) (im *Layer) {
|
||||
func New(key *prv.Key, ap *netip.AddrPort) (in *Layer) {
|
||||
pk := pub.Derive(key)
|
||||
bap, _ := ap.MarshalBinary()
|
||||
pkb := pk.ToBytes()
|
||||
@@ -47,7 +47,7 @@ func New(key *prv.Key, ap *netip.AddrPort) (im *Layer) {
|
||||
if sign, e = sig.Sign(key, hash); check(e) {
|
||||
return nil
|
||||
}
|
||||
im = &Layer{
|
||||
in = &Layer{
|
||||
Key: pk,
|
||||
AddrPort: ap,
|
||||
Bytes: sign,
|
||||
@@ -85,6 +85,7 @@ func (im *Layer) Encode(b slice.Bytes, c *slice.Cursor) {
|
||||
func (im *Layer) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
|
||||
splice.Splice(b, c).
|
||||
ReadPubkey(&im.Key).
|
||||
ReadAddrPort(&im.AddrPort).ReadSignature(im.Bytes)
|
||||
ReadAddrPort(&im.AddrPort).
|
||||
ReadSignature(&im.Bytes)
|
||||
return
|
||||
}
|
||||
|
||||
22
pkg/messages/intro/intro-message_test.go
Normal file
22
pkg/messages/intro/intro-message_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package intro
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/prv"
|
||||
"git-indra.lan/indra-labs/indra/pkg/util/slice"
|
||||
)
|
||||
|
||||
func TestLayer_Validate(t *testing.T) {
|
||||
addr := slice.GenerateRandomAddrPortIPv4()
|
||||
var e error
|
||||
var idPrv *prv.Key
|
||||
if idPrv, e = prv.GenerateKey(); check(e) {
|
||||
return
|
||||
}
|
||||
im := New(idPrv, addr)
|
||||
log.I.S(im)
|
||||
if !im.Validate() {
|
||||
t.Error("failed to validate")
|
||||
}
|
||||
}
|
||||
@@ -302,6 +302,7 @@ func TestClient_HiddenService(t *testing.T) {
|
||||
v.Shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_HiddenServiceBroadcast(t *testing.T) {
|
||||
log2.SetLogLevel(log2.Info)
|
||||
var clients []*Engine
|
||||
|
||||
@@ -13,5 +13,5 @@ func (eng *Engine) hiddenservice(hs *hiddenservice.Layer, b slice.Bytes,
|
||||
hs.Layer.Key.ToBase32())
|
||||
eng.Introductions.AddIntro(hs.Layer.Key, b[*c:])
|
||||
log.I.Ln("stored new introduction, starting broadcast")
|
||||
go eng.hiddenserviceBroadcaster(hs.Layer.Key)
|
||||
go eng.hiddenserviceBroadcaster(&hs.Layer)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
func (eng *Engine) intro(intr *intro.Layer, b slice.Bytes,
|
||||
c *slice.Cursor, prev types.Onion) {
|
||||
|
||||
log.D.F("sending out intro to %s at %s to all known peers",
|
||||
intr.Key.ToBase32(), intr.AddrPort.String())
|
||||
if intr.Validate() {
|
||||
log.D.F("sending out intro to %s at %s to all known peers",
|
||||
intr.Key.ToBase32(), intr.AddrPort.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
func (eng *Engine) SendIntro(id nonce.ID, target *Session, intr *intro.Layer,
|
||||
hook func(id nonce.ID, b slice.Bytes)) {
|
||||
|
||||
log.I.Ln(target.Hop)
|
||||
hops := []byte{0, 1, 2, 3, 4, 5}
|
||||
s := make(Sessions, len(hops))
|
||||
s[2] = target
|
||||
|
||||
@@ -13,12 +13,11 @@ import (
|
||||
|
||||
type Referrers map[pub.Bytes][]pub.Bytes
|
||||
|
||||
func (eng *Engine) hiddenserviceBroadcaster(hsk *pub.Key) {
|
||||
log.D.F("propagating hidden service introduction for %x", hsk.ToBytes())
|
||||
func (eng *Engine) hiddenserviceBroadcaster(hs *intro.Layer) {
|
||||
log.D.F("propagating hidden service introduction for %x", hs.Key.ToBytes())
|
||||
done := qu.T()
|
||||
me := eng.GetLocalNodeAddress()
|
||||
intr := &intro.Layer{
|
||||
Key: hsk, AddrPort: me,
|
||||
Key: hs.Key, AddrPort: hs.AddrPort, Bytes: hs.Bytes,
|
||||
}
|
||||
msg := make(slice.Bytes, intro.Len)
|
||||
c := slice.NewCursor()
|
||||
|
||||
@@ -183,7 +183,7 @@ func (s *Splicer) Signature(sb sig.Bytes) *Splicer {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Splicer) ReadSignature(sb sig.Bytes) *Splicer {
|
||||
func (s *Splicer) ReadSignature(sb *sig.Bytes) *Splicer {
|
||||
copy(sb[:], s.b[*s.c:s.c.Inc(sig.Len)])
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user