Skip to content

Commit

Permalink
Proxy running and syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
dix975 committed Aug 21, 2018
1 parent 9f5770a commit f297a12
Show file tree
Hide file tree
Showing 10 changed files with 741 additions and 491 deletions.
35 changes: 27 additions & 8 deletions cmd/eos-p2p-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
package main

import (
"log"
"net"

"encoding/hex"

"github.com/eoscanada/eos-go/p2p"
)

func peer(address string, chainID []byte) *p2p.Peer {

conn, err := net.Dial("tcp", address)
if err != nil {
log.Fatalf("Dial %s id: %s", address, err)
}

originConnection := p2p.NewConnection(address, chainID, "eos-proxy", conn)
return p2p.NewPeer(originConnection)

}

func main() {

proxy := p2p.Proxy{
Routes: []*p2p.Route{
{From: ":19876", To: "patrick.testnets.eoscanada.com:9876"},
},
Handlers: []p2p.Handler{
//p2p.StringLoggerHandler,
p2p.LoggerHandler,
},
chainID, err := hex.DecodeString("aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906")
if err != nil {
log.Fatal("Chain id:", err)
}

route := &p2p.Route{
Origin: peer("localhost:6789", chainID),
Destination: peer("localhost:9875", chainID),
}

proxy := p2p.NewProxy(route)

proxy.Start()

}
55 changes: 55 additions & 0 deletions cmd/freeze/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"encoding/hex"
"log"
"net"

"time"

"fmt"

"github.com/eoscanada/eos-go"
"github.com/eoscanada/eos-go/p2p"
)

func peer(address string, chainID []byte) *p2p.Peer {

conn, err := net.Dial("tcp", address)
if err != nil {
log.Fatalf("Dial %s id: %s", address, err)
}

originConnection := p2p.NewConnection(address, chainID, "eos-proxy", conn)
return p2p.NewPeer(originConnection)

}
func readMessage(connection *p2p.Connection, msgChannel chan *eos.P2PMessageEnvelope, errChannel chan error) {
for {
msg, err := connection.Read()
if err != nil {
errChannel <- fmt.Errorf("read message from %s: %s", connection., err)
}
msgChannel <- msg
}
}

func main() {

chainID, err := hex.DecodeString("9bf6c5d3610260507f3a37340c43ff186c1810c984e9ad0b99b6fb8d6a3c94a3")
if err != nil {
log.Fatal("Chain id:", err)
}

dummyHandshakeInfo := &p2p.HandshakeInfo{
HeadBlockID: make([]byte, 32),
HeadBlockNum: 0,
HeadBlockTime: time.Now(),
}
peer := peer("localhost:9876", chainID)
peer.Connection.SendHandshake(dummyHandshakeInfo)
fmt.Println("Handshake sent!")

select {}
fmt.Println("Done!")
}
2 changes: 1 addition & 1 deletion p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type MessageReflectTypes struct {
}

var messageAttributes = []MessageReflectTypes{
{Name: "Handshake", ReflectType: reflect.TypeOf(HandshakeMessage{})},
{Name: "handshake", ReflectType: reflect.TypeOf(HandshakeMessage{})},
{Name: "ChainSize", ReflectType: reflect.TypeOf(ChainSizeMessage{})},
{Name: "GoAway", ReflectType: reflect.TypeOf(GoAwayMessage{})},
{Name: "Time", ReflectType: reflect.TypeOf(TimeMessage{})},
Expand Down
Loading

0 comments on commit f297a12

Please sign in to comment.