Skip to content

Commit

Permalink
fix: protal protocol type error
Browse files Browse the repository at this point in the history
  • Loading branch information
fearlessfe authored and GrapeBaBa committed Feb 6, 2024
1 parent 17d1601 commit 8651f5b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Dockerfile.portal
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM golang:1.20.13 as builder
FROM --platform=linux/amd64 golang:1.20.13 as builder

WORKDIR /app

COPY . .

RUN go env -w GOPROXY=https://goproxy.cn,direct
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./cmd/hive/main.go


FROM ubuntu:22.04
FROM --platform=linux/amd64 ubuntu:22.04

COPY --from=builder /app/main /usr/local/bin/app

Expand Down
3 changes: 2 additions & 1 deletion cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/discover/portalwire"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/portalnetwork/storage/sqlite"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -61,7 +62,7 @@ func main() {

contentQueue := make(chan *discover.ContentElement, 50)

protocol, err := discover.NewPortalProtocol(config, "history", privateKey, contentStorage, contentQueue)
protocol, err := discover.NewPortalProtocol(config, string(portalwire.HistoryNetwork), privateKey, contentStorage, contentQueue)

if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions p2p/discover/portal_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (p *PortalProtocol) Start() error {
}

p.DiscV5.RegisterTalkHandler(p.protocolId, p.handleTalkRequest)
p.DiscV5.RegisterTalkHandler(portalwire.UTPNetwork, p.handleUtpTalkRequest)
p.DiscV5.RegisterTalkHandler(string(portalwire.UTPNetwork), p.handleUtpTalkRequest)

go p.table.loop()

Expand Down Expand Up @@ -307,7 +307,7 @@ func (p *PortalProtocol) setupUDPListening() (*net.UDPConn, error) {
}

p.log.Trace("send to target data", "ip", target.IP().String(), "port", target.UDP(), "bufLength", len(buf))
_, err := p.DiscV5.TalkRequest(target, portalwire.UTPNetwork, buf)
_, err := p.DiscV5.TalkRequest(target, string(portalwire.UTPNetwork), buf)
return len(buf), err
})

Expand Down
9 changes: 6 additions & 3 deletions p2p/discover/portal_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func setupLocalPortalNode(addr string, bootNodes []*enode.Node) (*PortalProtocol
}

contentQueue := make(chan *ContentElement, 50)
portalProtocol, err := NewPortalProtocol(conf, portalwire.HistoryNetwork, newkey(), &MockStorage{db: make(map[string][]byte)}, contentQueue)
portalProtocol, err := NewPortalProtocol(conf, string(portalwire.HistoryNetwork), newkey(), &MockStorage{db: make(map[string][]byte)}, contentQueue)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -75,8 +75,11 @@ func TestPortalWireProtocolUdp(t *testing.T) {
assert.NoError(t, err)
time.Sleep(10 * time.Second)

node1Addr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8777")
node2Addr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8778")
udpAddrStr1 := fmt.Sprintf("%s:%d", node1.localNode.Node().IP(), node1.localNode.Node().UDP())
udpAddrStr2 := fmt.Sprintf("%s:%d", node2.localNode.Node().IP(), node2.localNode.Node().UDP())

node1Addr, _ := utp.ResolveUTPAddr("utp", udpAddrStr1)
node2Addr, _ := utp.ResolveUTPAddr("utp", udpAddrStr2)

cid := uint32(12)
cliSendMsgWithCid := "there are connection id : 12!"
Expand Down
24 changes: 12 additions & 12 deletions p2p/discover/portalwire/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ package portalwire

//go:generate sszgen --path p2p/discover/portalwire/messages.go --exclude-objs BlockHeaderProof,PortalReceipts

// Protocol IDs for the portal protocol.
const (
StateNetwork = "0x500a"
HistoryNetwork = "0x500b"
TxGossipNetwork = "0x500c"
HeaderGossipNetwork = "0x500d"
CanonicalIndicesNetwork = "0x500e"
BeaconLightClientNetwork = "0x501a"
UTPNetwork = "0x757470"
Rendezvous = "0x72656e"
)

// Message codes for the portal protocol.
const (
PING byte = 0x00
Expand Down Expand Up @@ -50,6 +38,18 @@ const (
PerContentKeyOverhead = 4
)

// Protocol IDs for the portal protocol.
var (
StateNetwork = []byte{0x50, 0x0a}
HistoryNetwork = []byte{0x50, 0x0b}
TxGossipNetwork = []byte{0x50, 0x0c}
HeaderGossipNetwork = []byte{0x50, 0x0d}
CanonicalIndicesNetwork = []byte{0x50, 0x0e}
BeaconLightClientNetwork = []byte{0x50, 0x1a}
UTPNetwork = []byte{0x75, 0x74, 0x70}
Rendezvous = []byte{0x72, 0x65, 0x6e}
)

type ContentKV struct {
ContentKey []byte
Content []byte
Expand Down
2 changes: 1 addition & 1 deletion portalnetwork/history/history_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func genHistoryNetwork(addr string, bootNodes []*enode.Node) (*HistoryNetwork, e
panic("couldn't generate key: " + err.Error())
}

portalProtocol, err := discover.NewPortalProtocol(conf, portalwire.HistoryNetwork, key, &MockStorage{db: make(map[string][]byte)}, contentQueue)
portalProtocol, err := discover.NewPortalProtocol(conf, string(portalwire.HistoryNetwork), key, &MockStorage{db: make(map[string][]byte)}, contentQueue)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 8651f5b

Please sign in to comment.