restructured intro ad type
This commit is contained in:
@@ -39,8 +39,12 @@ type Intro struct {
|
|||||||
Sig crypto.SigBytes
|
Sig crypto.SigBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Intro) Account(res *sess.Data, sm *sess.Manager,
|
func (x *Intro) Account(
|
||||||
s *sessions.Data, last bool) (skip bool, sd *sessions.Data) {
|
res *sess.Data,
|
||||||
|
sm *sess.Manager,
|
||||||
|
s *sessions.Data,
|
||||||
|
last bool,
|
||||||
|
) (skip bool, sd *sessions.Data) {
|
||||||
|
|
||||||
res.ID = x.ID
|
res.ID = x.ID
|
||||||
return
|
return
|
||||||
@@ -52,8 +56,7 @@ func (x *Intro) Decode(s *splice.Splice) (e error) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.
|
s.ReadID(&x.ID).
|
||||||
ReadID(&x.ID).
|
|
||||||
ReadPubkey(&x.Key).
|
ReadPubkey(&x.Key).
|
||||||
ReadAddrPort(&x.AddrPort).
|
ReadAddrPort(&x.AddrPort).
|
||||||
ReadUint32(&x.RelayRate).
|
ReadUint32(&x.RelayRate).
|
||||||
@@ -78,8 +81,6 @@ func (x *Intro) GetOnion() interface{} { return x }
|
|||||||
func (x *Intro) Gossip(sm *sess.Manager, c qu.C) {
|
func (x *Intro) Gossip(sm *sess.Manager, c qu.C) {
|
||||||
log.D.F("propagating hidden service intro for %s",
|
log.D.F("propagating hidden service intro for %s",
|
||||||
x.Key.ToBased32Abbreviated())
|
x.Key.ToBased32Abbreviated())
|
||||||
//Gossip(x, sm, c)
|
|
||||||
//log.T.Ln("finished broadcasting intro")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Intro) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
|
func (x *Intro) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
|
||||||
@@ -120,23 +121,35 @@ func (x *Intro) Len() int { return IntroLen }
|
|||||||
func (x *Intro) Magic() string { return IntroMagic }
|
func (x *Intro) Magic() string { return IntroMagic }
|
||||||
|
|
||||||
func (x *Intro) Splice(s *splice.Splice) {
|
func (x *Intro) Splice(s *splice.Splice) {
|
||||||
s.ID(x.ID).
|
x.SpliceNoSig(s)
|
||||||
Pubkey(x.Key).
|
s.Signature(x.Sig)
|
||||||
AddrPort(x.AddrPort).
|
}
|
||||||
Uint32(x.RelayRate).
|
|
||||||
Uint16(x.Port).
|
func IntroSplice(
|
||||||
Uint64(uint64(x.Expiry.UnixNano())).
|
s *splice.Splice,
|
||||||
Signature(x.Sig)
|
id nonce.ID,
|
||||||
|
key *crypto.Pub,
|
||||||
|
ap *netip.AddrPort,
|
||||||
|
relayRate uint32,
|
||||||
|
port uint16,
|
||||||
|
expires time.Time,
|
||||||
|
) {
|
||||||
|
|
||||||
|
s.ID(id).
|
||||||
|
Pubkey(key).
|
||||||
|
AddrPort(ap).
|
||||||
|
Uint32(relayRate).
|
||||||
|
Uint16(port).
|
||||||
|
Time(expires)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Intro) SpliceNoSig(s *splice.Splice) {
|
||||||
|
IntroSplice(s, x.ID, x.Key, x.AddrPort, x.RelayRate, x.Port, x.Expiry)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Intro) Validate() bool {
|
func (x *Intro) Validate() bool {
|
||||||
s := splice.New(IntroLen - magic.Len)
|
s := splice.New(IntroLen - magic.Len)
|
||||||
s.ID(x.ID).
|
x.SpliceNoSig(s)
|
||||||
Pubkey(x.Key).
|
|
||||||
AddrPort(x.AddrPort).
|
|
||||||
Uint32(x.RelayRate).
|
|
||||||
Uint16(x.Port).
|
|
||||||
Uint64(uint64(x.Expiry.UnixNano()))
|
|
||||||
hash := sha256.Single(s.GetUntil(s.GetCursor()))
|
hash := sha256.Single(s.GetUntil(s.GetCursor()))
|
||||||
key, e := x.Sig.Recover(hash)
|
key, e := x.Sig.Recover(hash)
|
||||||
if fails(e) {
|
if fails(e) {
|
||||||
@@ -150,17 +163,18 @@ func (x *Intro) Validate() bool {
|
|||||||
|
|
||||||
func (x *Intro) Wrap(inner Onion) {}
|
func (x *Intro) Wrap(inner Onion) {}
|
||||||
|
|
||||||
func NewIntro(id nonce.ID, key *crypto.Prv, ap *netip.AddrPort,
|
func NewIntro(
|
||||||
relayRate uint32, port uint16, expires time.Time) (in *Intro) {
|
id nonce.ID,
|
||||||
|
key *crypto.Prv,
|
||||||
|
ap *netip.AddrPort,
|
||||||
|
relayRate uint32,
|
||||||
|
port uint16,
|
||||||
|
expires time.Time,
|
||||||
|
) (in *Intro) {
|
||||||
|
|
||||||
pk := crypto.DerivePub(key)
|
pk := crypto.DerivePub(key)
|
||||||
s := splice.New(IntroLen - magic.Len)
|
s := splice.New(IntroLen - magic.Len)
|
||||||
s.ID(id).
|
IntroSplice(s, id, pk, ap, relayRate, port, expires)
|
||||||
Pubkey(pk).
|
|
||||||
AddrPort(ap).
|
|
||||||
Uint32(relayRate).
|
|
||||||
Uint16(port).
|
|
||||||
Uint64(uint64(expires.UnixNano()))
|
|
||||||
hash := sha256.Single(s.GetUntil(s.GetCursor()))
|
hash := sha256.Single(s.GetUntil(s.GetCursor()))
|
||||||
var e error
|
var e error
|
||||||
var sign crypto.SigBytes
|
var sign crypto.SigBytes
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ import (
|
|||||||
"github.com/indra-labs/indra/pkg/util/slice"
|
"github.com/indra-labs/indra/pkg/util/slice"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOnionSkins_Intro(t *testing.T) {
|
func TestOnionSkins_IntroAd(t *testing.T) {
|
||||||
log2.SetLogLevel(log2.Debug)
|
log2.SetLogLevel(log2.Debug)
|
||||||
var e error
|
var e error
|
||||||
pr, ks, _ := crypto.NewSigner()
|
pr, ks, _ := crypto.NewSigner()
|
||||||
id := nonce.NewID()
|
id := nonce.NewID()
|
||||||
in := NewIntro(id, pr, slice.GenerateRandomAddrPortIPv6(), 0, 0, time.Now().Add(time.Hour))
|
in := NewIntro(id, pr, slice.GenerateRandomAddrPortIPv6(),
|
||||||
|
0, 0, time.Now().Add(time.Hour))
|
||||||
var prvs crypto.Privs
|
var prvs crypto.Privs
|
||||||
for i := range prvs {
|
for i := range prvs {
|
||||||
prvs[i] = ks.Next()
|
prvs[i] = ks.Next()
|
||||||
|
|||||||
50
pkg/engine/onions/adpeer_test.go
Normal file
50
pkg/engine/onions/adpeer_test.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package onions
|
||||||
|
|
||||||
|
//
|
||||||
|
//func TestOnionSkins_PeerAd(t *testing.T) {
|
||||||
|
// log2.SetLogLevel(log2.Debug)
|
||||||
|
// var e error
|
||||||
|
// pr, ks, _ := crypto.NewSigner()
|
||||||
|
// id := nonce.NewID()
|
||||||
|
// in := NewPeerAd(id, pr, slice.GenerateRandomAddrPortIPv6(),
|
||||||
|
// 0, 0, time.Now().Add(time.Hour))
|
||||||
|
// var prvs crypto.Privs
|
||||||
|
// for i := range prvs {
|
||||||
|
// prvs[i] = ks.Next()
|
||||||
|
// }
|
||||||
|
// var pubs crypto.Pubs
|
||||||
|
// for i := range pubs {
|
||||||
|
// pubs[i] = crypto.DerivePub(prvs[i])
|
||||||
|
// }
|
||||||
|
// on1 := Skins{}.
|
||||||
|
// PeerAd(id, pr, in.AddrPort, time.Now().Add(time.Hour))
|
||||||
|
// on1 = append(on1, &End{})
|
||||||
|
// on := on1.Assemble()
|
||||||
|
// s := Encode(on)
|
||||||
|
// log.D.S(s.GetAll().ToBytes())
|
||||||
|
// s.SetCursor(0)
|
||||||
|
// var onc coding.Codec
|
||||||
|
// if onc = Recognise(s); onc == nil {
|
||||||
|
// t.Error("did not unwrap")
|
||||||
|
// t.FailNow()
|
||||||
|
// }
|
||||||
|
// if e = onc.Decode(s); fails(e) {
|
||||||
|
// t.Error("did not decode")
|
||||||
|
// t.FailNow()
|
||||||
|
// }
|
||||||
|
// log.D.S(onc)
|
||||||
|
// var intro *PeerAd
|
||||||
|
// var ok bool
|
||||||
|
// if intro, ok = onc.(*PeerAd); !ok {
|
||||||
|
// t.Error("did not unwrap expected type")
|
||||||
|
// t.FailNow()
|
||||||
|
// }
|
||||||
|
// if intro.AddrPort.String() != in.AddrPort.String() {
|
||||||
|
// t.Errorf("addrport did not decode correctly")
|
||||||
|
// t.FailNow()
|
||||||
|
// }
|
||||||
|
// if !intro.Validate() {
|
||||||
|
// t.Errorf("received intro did not validate")
|
||||||
|
// t.FailNow()
|
||||||
|
// }
|
||||||
|
//}
|
||||||
Reference in New Issue
Block a user