Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Peer #7

Merged
merged 21 commits into from
May 13, 2017
Merged

Basic Peer #7

merged 21 commits into from
May 13, 2017

Conversation

bfbachmann
Copy link
Member

@bfbachmann bfbachmann commented May 6, 2017

What Changed:

  • Added cumuluspeer with MakeBasicHost functionality
  • Updated main.go to take host port number, IP address and target peer to connect to as command line arguments
  • Added tests for cumuluspeer
  • Added documentation for cumuluspeer to Wiki

Remaining TODOs

  • Update main and BasicStreamHandler to actually communicate useful information between peer and host

Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job for your first Go code!

@@ -0,0 +1,145 @@
package cumuluspeer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call this peer. We know it's cumulus because inside the cumulus folder. Short and succinct package names

const (
DefaultPort = 8765 // Cumulus peers communicate over this TCP port
CumulusProtocol = "/cumulate/0.0.1" // Cumulus communication protocol
DefaultIP = "127.0.0.1" // Default Host IP address if none given
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run gofmt here.


const (
DefaultPort = 8765 // Cumulus peers communicate over this TCP port
CumulusProtocol = "/cumulate/0.0.1" // Cumulus communication protocol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cumulate instead of cumulus?

// Create a Cumulus host.
// This may throw an error if we fail to create a key pair, a pid, or a new
// multiaddress.
func MakeBasicHost(ip string, port int) (host.Host, pstore.Peerstore, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should wrap host.Host with your own struct peer.Peer and return that here. Also use the pattern NewPeer rather than MakePeer

// Communicate with peers.
// TODO: Update this to do something useful. For now it just reads from the
// stream and writes back what it read.
func doCumulate(s net.Stream) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a method on the Peer struct
func (p *Peer) Receive(s net.String) {...}

@@ -0,0 +1,38 @@
package cumuluspeer_test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all files in the same folder have the same package name

import (
"testing"

cumuluspeer "github.com/ubclaunchpad/cumulus/cumuluspeer"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't need this import

)

// Tests if we can make a basic host on a valid TCP port
func TestMakeBasicHostValidPort(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestNew...

main.go Outdated
if *targetPeer == "" {
// No target was specified, wait for incoming connections
log.Info("No target provided. Listening for incoming connections...")
select {} // Hang until someone connects to us
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will hang this goroutine forever, is that what we want?

main.go Outdated
// when joining the Cumulus Network.
// port is the port to communicate over (defaults to peer.DefaultPort).
// ip is the public IP address of the this host.
targetPeer := flag.String("t", "", "target peer to connect to")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we know the IP and the port of the multiaddr can we infer the rest? A multiaddr as a CLI flag is an awkward ui

doCumulate(s)
}

// Communicate with peers.
Copy link
Contributor

@chadlagore chadlagore May 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: https://golang.org/doc/effective_go.html#commentary. Function comments start with function name, ie // doCumulate communicates with peers.

The first sentence should be a one-sentence summary that starts with the name being declared. If every doc comment begins with the name of the item it describes, the output of godoc can usefully be run through grep.

@coveralls
Copy link

Coverage Status

Coverage decreased (-32.7%) to 67.347% when pulling 4a89e2c on 1-cumulus-peer into 8fb32b0 on dev.

peer/peer.go Outdated
// Open a stream with the peer
stream, err := p.NewStream(context.Background(), peerid,
CumulusProtocol)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return stream, err if you aren't handling error

peer/peer.go Outdated
// NewPeer creates a Cumulus host with the given IP addr and TCP port.
// This may throw an error if we fail to create a key pair, a pid, or a new
// multiaddress.
func NewPeer(ip string, port int) (*Peer, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're making a package with one primary export (ie Peer) then just call the constructor New. Then you're calling peer.New(...) -- makes more sense semantically

@coveralls
Copy link

coveralls commented May 11, 2017

Coverage Status

Coverage decreased (-34.7%) to 65.306% when pulling 8b255ad on 1-cumulus-peer into 8fb32b0 on dev.

@bfbachmann bfbachmann changed the title 1 cumulus peer Basic Peer May 13, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-33.6%) to 66.434% when pulling 39543d8 on 1-cumulus-peer into 8fb32b0 on dev.

@jordanschalm jordanschalm merged commit 138b4a4 into dev May 13, 2017
@jordanschalm jordanschalm deleted the 1-cumulus-peer branch May 13, 2017 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants