Refactored ad.Ad interface to cert.Act since it resembles an Act at Law.
Added explanation of this naming showing it's more abstract meaning as well as how it applies to hidden services.
This commit is contained in:
21
pkg/ad/ad.go
21
pkg/ad/ad.go
@@ -1,21 +0,0 @@
|
||||
// Package ad is an interface for peer information advertisements.
|
||||
package ad
|
||||
|
||||
import (
|
||||
"github.com/indra-labs/indra/pkg/codec"
|
||||
"github.com/indra-labs/indra/pkg/crypto"
|
||||
log2 "github.com/indra-labs/indra/pkg/proc/log"
|
||||
)
|
||||
|
||||
var (
|
||||
log = log2.GetLogger()
|
||||
fails = log.E.Chk
|
||||
)
|
||||
|
||||
// Ad is an interface for the signed messages stored in the PeerStore of the
|
||||
// libp2p host inside an indra engine.
|
||||
type Ad interface {
|
||||
codec.Codec
|
||||
Sign(key *crypto.Prv) (e error)
|
||||
Validate() bool
|
||||
}
|
||||
40
pkg/cert/ad.go
Normal file
40
pkg/cert/ad.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Package cert is an interface for messages bearing signatures of network participants.
|
||||
package cert
|
||||
|
||||
import (
|
||||
"github.com/indra-labs/indra/pkg/codec"
|
||||
"github.com/indra-labs/indra/pkg/crypto"
|
||||
log2 "github.com/indra-labs/indra/pkg/proc/log"
|
||||
)
|
||||
|
||||
var (
|
||||
log = log2.GetLogger()
|
||||
fails = log.E.Chk
|
||||
)
|
||||
|
||||
// Act is an interface for the signed messages stored in the PeerStore of the
|
||||
// libp2p host inside an indra engine.
|
||||
//
|
||||
// Note the abstract name and the open ended possibility of composing this into
|
||||
// other types of contract documents. In the language of Law an Act is the
|
||||
// prototype of a declaration or claim, a land title is an example of a type of
|
||||
// Act.
|
||||
//
|
||||
// In Indra, this is a spam-resistant message type that invites validation and
|
||||
// indirectly spammy abuse of this message type in the gossip network will cause
|
||||
// banning and the eviction of the record.
|
||||
//
|
||||
// Hidden services introduction advertisement is an example of the hidden
|
||||
// service attesting to the provision of the referral messages found in the
|
||||
// package: pkg/codec/onion/hidden/services - These are expected to become far
|
||||
// more numerous than peer advertisments as they effectively designate a
|
||||
// listening server. These can be spam-controlled by having peers poke at the
|
||||
// service and dropping non-working intros and thus potentially leading to the
|
||||
// hidden service intro being evicted from the collective peerstore.
|
||||
//
|
||||
// todo: hidden service sessions...
|
||||
type Act interface {
|
||||
codec.Codec
|
||||
Sign(key *crypto.Prv) (e error)
|
||||
Validate() bool
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package engine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/indra-labs/indra/pkg/ad"
|
||||
"github.com/indra-labs/indra/pkg/cert"
|
||||
"github.com/indra-labs/indra/pkg/codec/ont"
|
||||
"github.com/indra-labs/indra/pkg/codec/reg"
|
||||
"github.com/indra-labs/indra/pkg/crypto"
|
||||
@@ -88,7 +88,7 @@ func New(p Params) (ng *Engine, e error) {
|
||||
}
|
||||
}
|
||||
na := ng.NodeAds
|
||||
a := []ad.Ad{na.Address, na.Load, na.Peer, na.Services}
|
||||
a := []cert.Act{na.Address, na.Load, na.Peer, na.Services}
|
||||
if ng.NodeAds, e = ads.GenerateAds(p.Node, 25); fails(e) {
|
||||
cancel()
|
||||
return
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/indra-labs/indra/pkg/ad"
|
||||
"github.com/indra-labs/indra/pkg/cert"
|
||||
"github.com/indra-labs/indra/pkg/codec/ad/load"
|
||||
"github.com/indra-labs/indra/pkg/util/slice"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
@@ -51,7 +51,7 @@ func (ng *Engine) SendAd(a slice.Bytes) (e error) {
|
||||
// SendAds dispatches all ads in NodeAds. Primarily called at startup.
|
||||
func (ng *Engine) SendAds() (e error) {
|
||||
na := ng.NodeAds
|
||||
ads := []ad.Ad{na.Address, na.Load, na.Peer, na.Services}
|
||||
ads := []cert.Act{na.Address, na.Load, na.Peer, na.Services}
|
||||
for i := range ads {
|
||||
s := splice.New(ads[i].Len())
|
||||
ads[i].Encode(s)
|
||||
@@ -292,7 +292,7 @@ func (ng *Engine) HandleAd(p *pubsub.Message) (e error) {
|
||||
// GetPeerRecord queries the peerstore for an ad from a given peer.ID and the ad
|
||||
// type key. The ad type keys are the same as the Magic of each ad type, to be
|
||||
// simple.
|
||||
func (ng *Engine) GetPeerRecord(id peer.ID, key string) (add ad.Ad, e error) {
|
||||
func (ng *Engine) GetPeerRecord(id peer.ID, key string) (add cert.Act, e error) {
|
||||
var a interface{}
|
||||
if a, e = ng.Listener.Host.Peerstore().Get(id, key); fails(e) {
|
||||
return
|
||||
@@ -315,8 +315,8 @@ func (ng *Engine) GetPeerRecord(id peer.ID, key string) (add ad.Ad, e error) {
|
||||
if e = c.Decode(s); fails(e) {
|
||||
return
|
||||
}
|
||||
if add, ok = c.(ad.Ad); !ok {
|
||||
e = errors.New(key + " peer record did not decode as Ad")
|
||||
if add, ok = c.(cert.Act); !ok {
|
||||
e = errors.New(key + " peer record did not decode as Act")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user