Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/devp2p/internal/v5test/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newConn(dest *enode.Node, log logger) *conn {
localNode: ln,
remote: dest,
remoteAddr: &net.UDPAddr{IP: dest.IP(), Port: dest.UDP()},
codec: v5wire.NewCodec(ln, key, mclock.System{}),
codec: v5wire.NewCodec(ln, key, mclock.System{}, nil),
log: log,
}
}
Expand Down
11 changes: 10 additions & 1 deletion console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/CortexFoundation/CortexTheseus/internal/jsre"
"github.com/CortexFoundation/CortexTheseus/internal/jsre/deps"
"github.com/CortexFoundation/CortexTheseus/internal/web3ext"
"github.com/CortexFoundation/CortexTheseus/log"
"github.com/CortexFoundation/CortexTheseus/rpc"
"github.com/dop251/goja"
"github.com/mattn/go-colorable"
Expand Down Expand Up @@ -180,12 +181,20 @@ func (c *Console) initWeb3(bridge *bridge) error {
return err
}

var defaultAPIs = map[string]string{"ctxc": "1.0", "net": "1.0", "debug": "1.0"}

// initExtensions loads and registers web3.js extensions.
func (c *Console) initExtensions() error {
const methodNotFound = -32601
// Compute aliases from server-provided modules.
apis, err := c.client.SupportedModules()
if err != nil {
return fmt.Errorf("api modules: %v", err)
if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == methodNotFound {
log.Warn("Server does not support method rpc_modules, using default API list.")
apis = defaultAPIs
} else {
return err
}
}
aliases := map[string]struct{}{"ctxc": {}, "personal": {}}
for api := range apis {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1
github.com/CortexFoundation/inference v1.0.2-0.20221114235728-985486629a61
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
github.com/CortexFoundation/torrentfs v1.0.35-0.20221121210641-607c9ddacb73
github.com/CortexFoundation/torrentfs v1.0.35-0.20221126200542-1ab479237bfe
github.com/VictoriaMetrics/fastcache v1.12.0
github.com/arsham/figurine v1.2.0
github.com/aws/aws-sdk-go-v2 v1.16.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66/go.mod h1:
github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.mod h1:Ma+tGhPPvz4CEZHaqEJQMOEGOfHeQBiAoNd1zyc/w3Q=
github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk=
github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
github.com/CortexFoundation/torrentfs v1.0.35-0.20221121210641-607c9ddacb73 h1:XDBtIn1ymeVpHYi/8+2fpikUZJvo5rv/fTnDzgZRg/M=
github.com/CortexFoundation/torrentfs v1.0.35-0.20221121210641-607c9ddacb73/go.mod h1:WMYeTsLSYxNlt1ecXI8yBl041roC03L4N201nOZZn7k=
github.com/CortexFoundation/torrentfs v1.0.35-0.20221126200542-1ab479237bfe h1:y6h08LLz75+aaOMJqyhM7KH+uPVYH3xQxPMY6In60sY=
github.com/CortexFoundation/torrentfs v1.0.35-0.20221126200542-1ab479237bfe/go.mod h1:WMYeTsLSYxNlt1ecXI8yBl041roC03L4N201nOZZn7k=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DATA-DOG/go-sqlmock v1.4.1 h1:ThlnYciV1iM/V0OSF/dtkqWb6xo5qITT1TJBG1MRDJM=
github.com/HdrHistogram/hdrhistogram-go v1.1.0 h1:6dpdDPTRoo78HxAJ6T1HfMiKSnqhgRRqzCuPshRkQ7I=
Expand Down
16 changes: 12 additions & 4 deletions p2p/discover/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,24 @@ type UDPConn interface {
LocalAddr() net.Addr
}

type V5Config struct {
ProtocolID *[6]byte
}

// Config holds settings for the discovery listener.
type Config struct {
// These settings are required and configure the UDP listener:
PrivateKey *ecdsa.PrivateKey

// These settings are optional:
NetRestrict *netutil.Netlist // list of allowed IP networks
Bootnodes []*enode.Node // list of bootstrap nodes
Unhandled chan<- ReadPacket // unhandled packets are sent on this channel
Log log.Logger // if set, log messages go here
NetRestrict *netutil.Netlist // list of allowed IP networks
Bootnodes []*enode.Node // list of bootstrap nodes
Unhandled chan<- ReadPacket // unhandled packets are sent on this channel
Log log.Logger // if set, log messages go here

// V5ProtocolID configures the discv5 protocol identifier.
V5ProtocolID *[6]byte

ValidSchemes enr.IdentityScheme // allowed identity schemes
Clock mclock.Clock
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/discover/v5_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func newUDPv5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
callDoneCh: make(chan *callV5),
respTimeoutCh: make(chan *callTimeout),
// state of dispatch
codec: v5wire.NewCodec(ln, cfg.PrivateKey, cfg.Clock),
codec: v5wire.NewCodec(ln, cfg.PrivateKey, cfg.Clock, cfg.V5ProtocolID),
activeCallByNode: make(map[enode.ID]*callV5),
activeCallByAuth: make(map[v5wire.Nonce]*callV5),
callQueue: make(map[enode.ID][]*callV5),
Expand Down
31 changes: 18 additions & 13 deletions p2p/discover/v5wire/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const (
randomPacketMsgSize = 20
)

var protocolID = [6]byte{'d', 'i', 's', 'c', 'v', '5'}
var DefaultProtocolID = [6]byte{'d', 'i', 's', 'c', 'v', '5'}

// Errors.
var (
Expand Down Expand Up @@ -134,10 +134,11 @@ var (
// Codec encodes and decodes Discovery v5 packets.
// This type is not safe for concurrent use.
type Codec struct {
sha256 hash.Hash
localnode *enode.LocalNode
privkey *ecdsa.PrivateKey
sc *SessionCache
sha256 hash.Hash
localnode *enode.LocalNode
privkey *ecdsa.PrivateKey
sc *SessionCache
protocolID [6]byte

// encoder buffers
buf bytes.Buffer // whole packet
Expand All @@ -150,12 +151,16 @@ type Codec struct {
}

// NewCodec creates a wire codec.
func NewCodec(ln *enode.LocalNode, key *ecdsa.PrivateKey, clock mclock.Clock) *Codec {
func NewCodec(ln *enode.LocalNode, key *ecdsa.PrivateKey, clock mclock.Clock, protocolID *[6]byte) *Codec {
c := &Codec{
sha256: sha256.New(),
localnode: ln,
privkey: key,
sc: NewSessionCache(1024, clock),
sha256: sha256.New(),
localnode: ln,
privkey: key,
sc: NewSessionCache(1024, clock),
protocolID: DefaultProtocolID,
}
if protocolID != nil {
c.protocolID = *protocolID
}
return c
}
Expand Down Expand Up @@ -255,7 +260,7 @@ func (c *Codec) makeHeader(toID enode.ID, flag byte, authsizeExtra int) Header {
}
return Header{
StaticHeader: StaticHeader{
ProtocolID: protocolID,
ProtocolID: c.protocolID,
Version: version,
Flag: flag,
AuthSize: uint16(authsize),
Expand Down Expand Up @@ -434,7 +439,7 @@ func (c *Codec) Decode(input []byte, addr string) (src enode.ID, n *enode.Node,
c.reader.Reset(staticHeader)
binary.Read(&c.reader, binary.BigEndian, &head.StaticHeader)
remainingInput := len(input) - sizeofStaticPacketData
if err := head.checkValid(remainingInput); err != nil {
if err := head.checkValid(remainingInput, c.protocolID); err != nil {
return enode.ID{}, nil, nil, err
}

Expand Down Expand Up @@ -621,7 +626,7 @@ func (c *Codec) decryptMessage(input, nonce, headerData, readKey []byte) (Packet

// checkValid performs some basic validity checks on the header.
// The packetLen here is the length remaining after the static header.
func (h *StaticHeader) checkValid(packetLen int) error {
func (h *StaticHeader) checkValid(packetLen int, protocolID [6]byte) error {
if h.ProtocolID != protocolID {
return errInvalidHeader
}
Expand Down
8 changes: 4 additions & 4 deletions p2p/discover/v5wire/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ type handshakeTestNode struct {

func newHandshakeTest() *handshakeTest {
t := new(handshakeTest)
t.nodeA.init(testKeyA, net.IP{127, 0, 0, 1}, &t.clock)
t.nodeB.init(testKeyB, net.IP{127, 0, 0, 1}, &t.clock)
t.nodeA.init(testKeyA, net.IP{127, 0, 0, 1}, &t.clock, DefaultProtocolID)
t.nodeB.init(testKeyB, net.IP{127, 0, 0, 1}, &t.clock, DefaultProtocolID)
return t
}

Expand All @@ -514,11 +514,11 @@ func (t *handshakeTest) close() {
t.nodeB.ln.Database().Close()
}

func (n *handshakeTestNode) init(key *ecdsa.PrivateKey, ip net.IP, clock mclock.Clock) {
func (n *handshakeTestNode) init(key *ecdsa.PrivateKey, ip net.IP, clock mclock.Clock, protocolID [6]byte) {
db, _ := enode.OpenDB("")
n.ln = enode.NewLocalNode(db, key)
n.ln.SetStaticIP(ip)
n.c = NewCodec(n.ln, key, clock)
n.c = NewCodec(n.ln, key, clock, nil)
}

func (n *handshakeTestNode) encode(t testing.TB, to handshakeTestNode, p Packet) ([]byte, Nonce) {
Expand Down
25 changes: 19 additions & 6 deletions vendor/github.com/CortexFoundation/torrentfs/backend/handler.go

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ github.com/CortexFoundation/merkletree
# github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
## explicit; go 1.16
github.com/CortexFoundation/statik
# github.com/CortexFoundation/torrentfs v1.0.35-0.20221121210641-607c9ddacb73
# github.com/CortexFoundation/torrentfs v1.0.35-0.20221126200542-1ab479237bfe
## explicit; go 1.19
github.com/CortexFoundation/torrentfs
github.com/CortexFoundation/torrentfs/backend
Expand Down