-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chain nodes relay indexer pubsub messages.
This includes message validation and rate-limiting.
- Loading branch information
Showing
12 changed files
with
689 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.