Skip to content

Commit

Permalink
Chain nodes relay indexer pubsub messages.
Browse files Browse the repository at this point in the history
This includes message validation and rate-limiting.
  • Loading branch information
gammazero committed Feb 25, 2022
1 parent 949a046 commit 0da49b9
Show file tree
Hide file tree
Showing 12 changed files with 689 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build/params_shared_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import (

func BlocksTopic(netName dtypes.NetworkName) string { return "/fil/blocks/" + string(netName) }
func MessagesTopic(netName dtypes.NetworkName) string { return "/fil/msgs/" + string(netName) }
func IndexerIngestTopic(netName dtypes.NetworkName) string {
nn := string(netName)
// The network name testnetnet is here for historical reasons.
// Going forward we aim to use the name `mainnet` where possible.
if nn == "testnetnet" {
nn = "mainnet"
}

return "/indexer/ingest/" + nn
}
func DhtProtocolName(netName dtypes.NetworkName) protocol.ID {
return protocol.ID("/fil/kad/" + string(netName))
}
Expand Down
176 changes: 176 additions & 0 deletions chain/sub/idxmsg/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions chain/sub/idxmsg/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Package idxmsg is a copy of the message and codec from go-legs v0.3.0. It is
// copied here because having a dependency on go-legs v0.3.0 brings other
// incompatible dependencies. The code here was copied from:
//
// https://github.com/filecoin-project/go-legs/tree/main/dtsync
package idxmsg

import (
"errors"

"github.com/ipfs/go-cid"
"github.com/multiformats/go-multiaddr"
)

var ErrBadEncoding = errors.New("invalid message encoding")

type Message struct {
Cid cid.Cid
Addrs [][]byte
ExtraData []byte `json:",omitempty"`
}

func (m *Message) SetAddrs(addrs []multiaddr.Multiaddr) {
m.Addrs = make([][]byte, 0, len(addrs))
for _, a := range addrs {
m.Addrs = append(m.Addrs, a.Bytes())
}
}

func (m *Message) GetAddrs() ([]multiaddr.Multiaddr, error) {
addrs := make([]multiaddr.Multiaddr, 0, len(m.Addrs))
for _, a := range m.Addrs {
p, err := multiaddr.NewMultiaddrBytes(a)
if err != nil {
return nil, err
}
addrs = append(addrs, p)
}
return addrs, nil
}
Loading

0 comments on commit 0da49b9

Please sign in to comment.