From e09c870f7fa4f9076514e21bddb94f6b56135e74 Mon Sep 17 00:00:00 2001 From: Steven Jack Date: Sat, 3 Mar 2018 07:16:05 +0000 Subject: [PATCH] Fix bug where channel for peers events is called after it's closed (#34) * Disconnect once go routines signal so * Send msg if cmd is other than cmdUnknown * Remove typo * Fix lock file * Updates README * Comment typo * Fix issue * Revert old changes * Handle error --- Makefile | 7 ++++++- README.md | 10 ++++++++-- pkg/network/message.go | 23 +++++++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 8171d1195..7cc8e0666 100644 --- a/Makefile +++ b/Makefile @@ -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 ./... \ No newline at end of file + @go vet ./... diff --git a/README.md b/README.md index 813dd8a2f..97e958a0c 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/pkg/network/message.go b/pkg/network/message.go index 06fb6e87c..ae484f58a 100644 --- a/pkg/network/message.go +++ b/pkg/network/message.go @@ -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 {