restructured intro ad type
This commit is contained in:
@@ -39,8 +39,12 @@ type Intro struct {
|
||||
Sig crypto.SigBytes
|
||||
}
|
||||
|
||||
func (x *Intro) Account(res *sess.Data, sm *sess.Manager,
|
||||
s *sessions.Data, last bool) (skip bool, sd *sessions.Data) {
|
||||
func (x *Intro) Account(
|
||||
res *sess.Data,
|
||||
sm *sess.Manager,
|
||||
s *sessions.Data,
|
||||
last bool,
|
||||
) (skip bool, sd *sessions.Data) {
|
||||
|
||||
res.ID = x.ID
|
||||
return
|
||||
@@ -52,8 +56,7 @@ func (x *Intro) Decode(s *splice.Splice) (e error) {
|
||||
|
||||
return
|
||||
}
|
||||
s.
|
||||
ReadID(&x.ID).
|
||||
s.ReadID(&x.ID).
|
||||
ReadPubkey(&x.Key).
|
||||
ReadAddrPort(&x.AddrPort).
|
||||
ReadUint32(&x.RelayRate).
|
||||
@@ -78,8 +81,6 @@ func (x *Intro) GetOnion() interface{} { return x }
|
||||
func (x *Intro) Gossip(sm *sess.Manager, c qu.C) {
|
||||
log.D.F("propagating hidden service intro for %s",
|
||||
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) {
|
||||
@@ -120,23 +121,35 @@ func (x *Intro) Len() int { return IntroLen }
|
||||
func (x *Intro) Magic() string { return IntroMagic }
|
||||
|
||||
func (x *Intro) Splice(s *splice.Splice) {
|
||||
s.ID(x.ID).
|
||||
Pubkey(x.Key).
|
||||
AddrPort(x.AddrPort).
|
||||
Uint32(x.RelayRate).
|
||||
Uint16(x.Port).
|
||||
Uint64(uint64(x.Expiry.UnixNano())).
|
||||
Signature(x.Sig)
|
||||
x.SpliceNoSig(s)
|
||||
s.Signature(x.Sig)
|
||||
}
|
||||
|
||||
func IntroSplice(
|
||||
s *splice.Splice,
|
||||
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 {
|
||||
s := splice.New(IntroLen - magic.Len)
|
||||
s.ID(x.ID).
|
||||
Pubkey(x.Key).
|
||||
AddrPort(x.AddrPort).
|
||||
Uint32(x.RelayRate).
|
||||
Uint16(x.Port).
|
||||
Uint64(uint64(x.Expiry.UnixNano()))
|
||||
x.SpliceNoSig(s)
|
||||
hash := sha256.Single(s.GetUntil(s.GetCursor()))
|
||||
key, e := x.Sig.Recover(hash)
|
||||
if fails(e) {
|
||||
@@ -150,17 +163,18 @@ func (x *Intro) Validate() bool {
|
||||
|
||||
func (x *Intro) Wrap(inner Onion) {}
|
||||
|
||||
func NewIntro(id nonce.ID, key *crypto.Prv, ap *netip.AddrPort,
|
||||
relayRate uint32, port uint16, expires time.Time) (in *Intro) {
|
||||
func NewIntro(
|
||||
id nonce.ID,
|
||||
key *crypto.Prv,
|
||||
ap *netip.AddrPort,
|
||||
relayRate uint32,
|
||||
port uint16,
|
||||
expires time.Time,
|
||||
) (in *Intro) {
|
||||
|
||||
pk := crypto.DerivePub(key)
|
||||
s := splice.New(IntroLen - magic.Len)
|
||||
s.ID(id).
|
||||
Pubkey(pk).
|
||||
AddrPort(ap).
|
||||
Uint32(relayRate).
|
||||
Uint16(port).
|
||||
Uint64(uint64(expires.UnixNano()))
|
||||
IntroSplice(s, id, pk, ap, relayRate, port, expires)
|
||||
hash := sha256.Single(s.GetUntil(s.GetCursor()))
|
||||
var e error
|
||||
var sign crypto.SigBytes
|
||||
|
||||
@@ -11,12 +11,13 @@ import (
|
||||
"github.com/indra-labs/indra/pkg/util/slice"
|
||||
)
|
||||
|
||||
func TestOnionSkins_Intro(t *testing.T) {
|
||||
func TestOnionSkins_IntroAd(t *testing.T) {
|
||||
log2.SetLogLevel(log2.Debug)
|
||||
var e error
|
||||
pr, ks, _ := crypto.NewSigner()
|
||||
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
|
||||
for i := range prvs {
|
||||
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