fix version conflict and removed output file from wallet as its relocated in transaction package.

This commit is contained in:
anthdm 2018-03-04 14:53:01 +01:00
commit dc83b584be
7 changed files with 61 additions and 106 deletions

View file

@ -1,5 +1,7 @@
BRANCH = "master"
VERSION = $(shell cat ./VERSION)
SEEDS ?= "127.0.0.1:20333"
PORT ?= "3000"
build:
@go build -o ./bin/neo-go ./cli/main.go
@ -16,8 +18,11 @@ push-tag:
git tag ${VERSION}
git push origin ${BRANCH} --tags
run: build
./bin/neo-go node -seed ${SEEDS} -tcp ${PORT}
test:
@go test ./... -cover
vet:
@go vet ./...
@go vet ./...

View file

@ -75,18 +75,24 @@ If you dont, take a look at [docker-privnet-with-gas](https://hub.docker.com/r/m
Start a NEO node:
```
./bin/neo-go node -seed 127.0.0.1:20333
make run
```
You can add multiple seeds if you want:
```
./bin/neo-go node -seed 127.0.0.1:20333,127.0.01:20334
make run -e SEEDS="127.0.0.1:20333,127.0.01:20334"
```
By default the server will currently run on port 3000, for testing purposes.
You can change that by setting the tcp flag:
```
make run -e PORT="1337"
```
To run the binary directly:
```
./bin/neo-go node -seed 127.0.0.1:20333 -tcp 1337
```

View file

@ -141,10 +141,25 @@ func (m *Message) commandType() commandType {
// decode a Message from the given reader.
func (m *Message) decode(r io.Reader) error {
binary.Read(r, binary.LittleEndian, &m.Magic)
binary.Read(r, binary.LittleEndian, &m.Command)
binary.Read(r, binary.LittleEndian, &m.Length)
binary.Read(r, binary.LittleEndian, &m.Checksum)
err := binary.Read(r, binary.LittleEndian, &m.Magic)
if err != nil {
return err
}
err = binary.Read(r, binary.LittleEndian, &m.Command)
if err != nil {
return err
}
err = binary.Read(r, binary.LittleEndian, &m.Length)
if err != nil {
return err
}
err = binary.Read(r, binary.LittleEndian, &m.Checksum)
if err != nil {
return err
}
// return if their is no payload.
if m.Length == 0 {

View file

@ -11,13 +11,8 @@ type Peer interface {
id() uint32
addr() util.Endpoint
disconnect()
Send(*Message) error
version() *payload.Version
callVersion(*Message) error
callGetaddr(*Message) error
callVerack(*Message) error
callGetdata(*Message) error
callGetblocks(*Message) error
callGetheaders(*Message) error
}
// LocalPeer is the simplest kind of peer, mapped to a server in the
@ -35,36 +30,23 @@ func NewLocalPeer(s *Server) *LocalPeer {
return &LocalPeer{endpoint: e, s: s}
}
func (p *LocalPeer) Send(msg *Message) error {
switch msg.commandType() {
case cmdVersion:
version := msg.Payload.(*payload.Version)
return p.s.handleVersionCmd(version, p)
case cmdGetAddr:
return p.s.handleGetaddrCmd(msg, p)
default:
return nil
}
}
// Version implements the Peer interface.
func (p *LocalPeer) version() *payload.Version {
return p.pVersion
}
func (p *LocalPeer) callVersion(msg *Message) error {
version := msg.Payload.(*payload.Version)
return p.s.handleVersionCmd(version, p)
}
func (p *LocalPeer) callVerack(msg *Message) error {
return nil
}
func (p *LocalPeer) callGetaddr(msg *Message) error {
return p.s.handleGetaddrCmd(msg, p)
}
func (p *LocalPeer) callGetblocks(msg *Message) error {
return nil
}
func (p *LocalPeer) callGetheaders(msg *Message) error {
return nil
}
func (p *LocalPeer) callGetdata(msg *Message) error {
return nil
}
func (p *LocalPeer) id() uint32 { return p.nonce }
func (p *LocalPeer) addr() util.Endpoint { return p.endpoint }
func (p *LocalPeer) disconnect() {}

View file

@ -209,7 +209,7 @@ func (s *Server) handlePeerConnected(p Peer) error {
// TODO: get the blockheight of this server once core implemented this.
payload := payload.NewVersion(s.id, s.port, s.userAgent, s.bc.HeaderHeight(), s.relay)
msg := newMessage(s.net, cmdVersion, payload)
return p.callVersion(msg)
return p.Send(msg)
}
func (s *Server) handleVersionCmd(version *payload.Version, p Peer) error {
@ -220,7 +220,9 @@ func (s *Server) handleVersionCmd(version *payload.Version, p Peer) error {
return fmt.Errorf("port mismatch: %d and %d", version.Port, p.addr().Port)
}
return p.callVerack(newMessage(s.net, cmdVerack, nil))
return p.Send(
newMessage(s.net, cmdVerack, nil),
)
}
func (s *Server) handleGetaddrCmd(msg *Message, p Peer) error {
@ -242,7 +244,7 @@ func (s *Server) handleInvCmd(inv *payload.Inventory, p Peer) error {
payload := payload.NewInventory(inv.Type, inv.Hashes)
resp := newMessage(s.net, cmdGetData, payload)
return p.callGetdata(resp)
return p.Send(resp)
}
// handleBlockCmd processes the received block.
@ -297,7 +299,7 @@ func (s *Server) askMoreHeaders(p Peer) error {
payload := payload.NewGetBlocks(start, util.Uint256{})
msg := newMessage(s.net, cmdGetHeaders, payload)
return p.callGetheaders(msg)
return p.Send(msg)
}
// check if the addr is already connected to the server.
@ -318,7 +320,7 @@ func (s *Server) startProtocol(p Peer) {
}
for {
getaddrMsg := newMessage(s.net, cmdGetAddr, nil)
p.callGetaddr(getaddrMsg)
p.Send(getaddrMsg)
time.Sleep(30 * time.Second)
}
@ -351,10 +353,10 @@ type StartOpts struct {
func logo() string {
return `
_ ____________ __________
_ ____________ __________
/ | / / ____/ __ \ / ____/ __ \
/ |/ / __/ / / / /_____/ / __/ / / /
/ /| / /___/ /_/ /_____/ /_/ / /_/ /
/_/ |_/_____/\____/ \____/\____/
/ /| / /___/ /_/ /_____/ /_/ / /_/ /
/_/ |_/_____/\____/ \____/\____/
`
}

View file

@ -181,7 +181,10 @@ func NewTCPPeer(conn net.Conn, s *Server) *TCPPeer {
}
}
func (p *TCPPeer) callVersion(msg *Message) error {
// Send needed to implement the network.Peer interface
// and provide the functionality to send a message to
// the current peer.
func (p *TCPPeer) Send(msg *Message) error {
t := sendTuple{
msg: msg,
err: make(chan error),
@ -206,64 +209,6 @@ func (p *TCPPeer) addr() util.Endpoint {
return p.endpoint
}
// callGetaddr will send the "getaddr" command to the remote.
func (p *TCPPeer) callGetaddr(msg *Message) error {
t := sendTuple{
msg: msg,
err: make(chan error),
}
p.send <- t
return <-t.err
}
// callGetblocks will send the "getblocks" command to the remote.
func (p *TCPPeer) callGetblocks(msg *Message) error {
t := sendTuple{
msg: msg,
err: make(chan error),
}
p.send <- t
return <-t.err
}
// callGetheaders will send the "getheaders" command to the remote.
func (p *TCPPeer) callGetheaders(msg *Message) error {
t := sendTuple{
msg: msg,
err: make(chan error),
}
p.send <- t
return <-t.err
}
func (p *TCPPeer) callVerack(msg *Message) error {
t := sendTuple{
msg: msg,
err: make(chan error),
}
p.send <- t
return <-t.err
}
func (p *TCPPeer) callGetdata(msg *Message) error {
t := sendTuple{
msg: msg,
err: make(chan error),
}
p.send <- t
return <-t.err
}
// disconnect disconnects the peer, cleaning up all its resources.
// 3 goroutines needs to be cleanup (writeLoop, handleConnection and handleMessage)
func (p *TCPPeer) disconnect() {

View file

@ -1,6 +1,6 @@
package wallet
import "github.com/anthdm/neo-go/pkg/util"
import "github.com/CityOfZion/neo-go/pkg/util"
// Account represents a NEO account. It holds the private and public key
// along with some metadata.