net-io

(after #442)

This PR changes net to use `io` instead of channels.
At the moment it's just `conn`, but soon more.
https://github.com/jbenet/go-ipfs/blob/53a1f4e7a639fb1b5acaaa52d38450b497bee157/net/mock/mock.go#L13
<--

`New` belongs with the struct in mock_net.go so i'll keep it there. godoc
is great though:

```
PACKAGE DOCUMENTATION

package mocknet
    import "."

    Package mocknet provides a mock net.Network to test with.

    - a Mocknet has many inet.Networks - a Mocknet has many Links - a Link
    joins two inet.Networks - inet.Conns and inet.Streams are created by
    inet.Networks

TYPES

type Link interface {
    Networks() []inet.Network
    Peers() []peer.Peer

    SetOptions(LinkOptions)
    Options() LinkOptions
}

type LinkOptions struct {
    Latency   time.Duration
    Bandwidth int // in bytes-per-second

}

type Mocknet interface {
    GenPeer() (inet.Network, error)
    AddPeer(peer.ID) (inet.Network, error)

    // retrieve things
    Peer(peer.ID) peer.Peer
    Peers() []peer.Peer
    Net(peer.ID) inet.Network
    Nets() []inet.Network
    LinksBetweenPeers(a, b peer.Peer) []Link
    LinksBetweenNets(a, b inet.Network) []Link

    PrintLinkMap(io.Writer)

    // Links are the **ability to connect**.
    // think of Links as the physical medium.
    // For p1 and p2 to connect, a link must exist between them.
    // (this makes it possible to test dial failures, and
    // things like relaying traffic)
    LinkPeers(peer.Peer, peer.Peer) (Link, error)
    LinkNets(inet.Network, inet.Network) (Link, error)
    Unlink(Link) error
    UnlinkPeers(peer.Peer, peer.Peer) error
    UnlinkNets(inet.Network, inet.Network) error

    // LinkDefaults are the default options that govern links
    // if they do not have thier own option set.
    SetLinkDefaults(LinkOptions)
    LinkDefaults() LinkOptions

    // Connections are the usual. Connecting means Dialing.
    // **to succeed, peers must be linked beforehand**
    ConnectPeers(peer.Peer, peer.Peer) error
    ConnectNets(inet.Network, inet.Network) error
    DisconnectPeers(peer.Peer, peer.Peer) error
    DisconnectNets(inet.Network, inet.Network) error
}

func FullMeshConnected(ctx context.Context, n int) (Mocknet, error)
    FullMeshConnected constructs a Mocknet with full mesh of Connections.
    This means that all the peers have dialed and are ready to talk to each
    other.

func FullMeshLinked(ctx context.Context, n int) (Mocknet, error)
    FullMeshLinked constructs a Mocknet with full mesh of Links. This means
    that all the peers **can** connect to each other (not that they already
    are connected. you can use m.ConnectAll())

func New(ctx context.Context) Mocknet

func WithNPeers(ctx context.Context, n int) (Mocknet, error)
    WithNPeers constructs a Mocknet with N peers.

```

On Wed, Dec 17, 2014 at 9:03 AM, Brian Tiger Chow <notifications@github.com>
wrote:
>
> In net/mock/mock.go
> <https://github.com/jbenet/go-ipfs/pull/443#discussion-diff-21986570>:
>
> > +func (c *Conn) RemotePeer() peer.Peer {
> > +	return c.remote.local
> > +}
> > +
> > +// network implements the Network interface,
> > +type Network struct {
> > +	local peer.Peer // local peer
> > +	mux   inet.Mux  // protocol multiplexing
> > +
> > +	conns map[peer.Peer]*Conn
> > +	sync.RWMutex
> > +
> > +	cg ctxgroup.ContextGroup // for Context closing
> > +}
> > +
> > +func MakeNetworks(ctx context.Context, peers []peer.Peer) (nets []*Network, err error) {
>
> AHHH. I'm so excited.
>
> I looked in mock.go and only saw three constructors.
>
>
> https://github.com/jbenet/go-ipfs/blob/53a1f4e7a639fb1b5acaaa52d38450b497bee157/net/mock/mock.go
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/jbenet/go-ipfs/pull/443/files#r21986570>.
>