From 55a9dc5febdc964e395394f64501a19099029d97 Mon Sep 17 00:00:00 2001 From: anthdm Date: Mon, 29 Jan 2018 08:11:08 +0100 Subject: [PATCH] Added extra comments. --- README.md | 3 +++ pkg/network/server.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 114df5fb7..23a4b53a7 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,6 @@ Make sure you have a private net running. If you dont, take a look at [docker-pr The only thing the server currently will do is asking for peers and connect to the responded peers. All other messages are in development. +# Contributing +todo. + diff --git a/pkg/network/server.go b/pkg/network/server.go index 6b3494258..1bd29c1ad 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -140,17 +140,21 @@ func (s *Server) loop() { for { select { case peer := <-s.register: + // When a new connection is been established, (by this server or remote node) + // its peer will be received on this channel. + // Any peer registration must happen via this channel. s.logger.Printf("peer registered from address %s", peer.conn.RemoteAddr()) s.peers[peer] = true - // only respond with the version mesage if the peer initiated the connection. + // Only respond with a version message if the peer initiated the connection. if peer.initiator { resp, err := s.handlePeerConnected() if err != nil { s.logger.Fatalf("handling initial peer connection failed: %s", err) + } else { + peer.send <- resp } - peer.send <- resp } case peer := <-s.unregister: // unregister should take care of all the cleanup that has to be made. @@ -161,6 +165,8 @@ func (s *Server) loop() { s.logger.Printf("peer %s disconnected", peer.conn.RemoteAddr()) } case tuple := <-s.message: + // When a remote node sends data over its connection it will be received + // on this channel. if err := s.processMessage(tuple.msg, tuple.peer); err != nil { s.logger.Fatalf("failed to process message: %s", err) s.disconnect(tuple.peer)