Commit 2b479e7f authored by Jeromy's avatar Jeromy

extract from go-libp2p

parent 9d52177d
os:
- linux
- osx
language: go
go:
- 1.7
install: true
before_install:
- make deps
script:
- go vet
- $GOPATH/bin/goveralls -service="travis-ci"
cache:
directories:
- $GOPATH/src/gx
notifications:
email: false
The MIT License (MIT)
Copyright (c) 2016 Jeromy Johnson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
export IPFS_API ?= v04x.ipfs.io
gx:
go get github.com/whyrusleeping/gx
go get github.com/whyrusleeping/gx-go
covertools:
go get github.com/mattn/goveralls
go get golang.org/x/tools/cmd/cover
deps: gx covertools
gx --verbose install --global
gx-go rewrite
publish:
gx-go rewrite --undo
go-libp2p-swarm
==================
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/go-libp2p-swarm/badge.svg?branch=master)](https://coveralls.io/github/libp2p/go-libp2p-swarm?branch=master)
[![Travis CI](https://travis-ci.org/libp2p/go-libp2p-swarm.svg?branch=master)](https://travis-ci.org/libp2p/go-libp2p-swarm)
> The libp2p swarm manages groups of connections to peers, and handles incoming and outgoing streams.
## Table of Contents
- [Install](#install)
- [Contribute](#contribute)
- [License](#license)
## Install
```sh
make install
```
## Contribute
PRs are welcome!
Small note: If editing the Readme, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
MIT © Jeromy Johnson
{
"author": "whyrusleeping",
"bugs": {
"url": "https://github.com/libp2p/go-libp2p-swarm"
},
"gx": {
"dvcsimport": "github.com/libp2p/go-libp2p-swarm"
},
"gxDependencies": [
{
"author": "whyrusleeping",
"hash": "QmdXimY9QHaasZmw6hWojWnCJvfgxETjZQfg9g6ZrA9wMX",
"name": "go-libp2p-net",
"version": "1.2.1"
},
{
"author": "whyrusleeping",
"hash": "QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46",
"name": "go-libp2p-crypto",
"version": "1.3.1"
},
{
"author": "whyrusleeping",
"hash": "QmXXCcQ7CLg5a81Ui9TTR35QcR4y7ZyihxwfjqaHfUVcVo",
"name": "go-libp2p-peerstore",
"version": "1.3.0"
},
{
"author": "whyrusleeping",
"hash": "QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP",
"name": "goprocess",
"version": "1.0.0"
},
{
"author": "whyrusleeping",
"hash": "QmWMia2fBVBesMerbtApQY7Tj2sgTaziveBACfCRUcv45f",
"name": "go-libp2p-transport",
"version": "2.2.1"
},
{
"author": "whyrusleeping",
"hash": "QmfXgTygwsTPyUWPWTAeBK6cFtTdMqmeeqhyhcNMhRpT1g",
"name": "go-smux-spdystream",
"version": "1.1.1"
},
{
"author": "whyrusleeping",
"hash": "Qme8hbiTP4VNr1s7FxsfnnqrxbxPz3KPWtuGYeGbtFnhGC",
"name": "go-smux-multistream",
"version": "1.3.1"
},
{
"author": "whyrusleeping",
"hash": "QmSHTSkxXGQgaHWz91oZV3CDy3hmKmDgpjbYRT6niACG4E",
"name": "go-smux-yamux",
"version": "1.1.1"
},
{
"author": "whyrusleeping",
"hash": "QmSC7uaj9igPHBEBRVD48iahCe3kBrywsmSaU4FesHgXWn",
"name": "ws-transport",
"version": "1.4.1"
},
{
"author": "whyrusleeping",
"hash": "QmSMZwvs3n4GBikZ7hKzT17c3bk65FmyZo2JqtJ16swqCv",
"name": "multiaddr-filter",
"version": "1.0.2"
},
{
"author": "whyrusleeping",
"hash": "QmRmFKJgjjQhrT1uDyhpS87kE5M9YbMT8RBWam5uk8o4uH",
"name": "go-peerstream",
"version": "1.1.0"
},
{
"author": "whyrusleeping",
"hash": "QmWpTXhTkpoCDEm9twJd5Rc9jFwy61emzxneeJzrVMfjGF",
"name": "go-libp2p-metrics",
"version": "1.2.0"
},
{
"author": "whyrusleeping",
"hash": "QmdiBXu57LDzaoovc89jypRSNEhxVZ4zRig2AsXm9VwrsS",
"name": "go-libp2p-conn",
"version": "1.2.1"
},
{
"author": "whyrusleeping",
"hash": "QmNiFRHdeJgN9svSGkEtmhd5sGvv3suSKZ1sRkLqoCzL76",
"name": "go-tcp-transport",
"version": "1.1.0"
}
],
"gxVersion": "0.9.1",
"language": "go",
"license": "",
"name": "go-libp2p-swarm",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "0.0.0"
}
package swarm_test
package swarm
import (
"context"
"fmt"
"testing"
"time"
"context"
inet "github.com/libp2p/go-libp2p-net"
testutil "github.com/libp2p/go-libp2p/p2p/test/util"
pstore "github.com/libp2p/go-libp2p-peerstore"
tu "github.com/libp2p/go-testutil"
ma "github.com/multiformats/go-multiaddr"
)
func GenSwarmNetwork(t *testing.T, ctx context.Context) *Network {
p := tu.RandPeerNetParamsOrFatal(t)
ps := pstore.NewPeerstore()
ps.AddPubKey(p.ID, p.PubKey)
ps.AddPrivKey(p.ID, p.PrivKey)
n, err := NewNetwork(ctx, []ma.Multiaddr{p.Addr}, p.ID, ps, nil)
if err != nil {
t.Fatal(err)
}
ps.AddAddrs(p.ID, n.ListenAddresses(), pstore.PermanentAddrTTL)
return n
}
func DivulgeAddresses(a, b inet.Network) {
id := a.LocalPeer()
addrs := a.Peerstore().Addrs(id)
b.Peerstore().AddAddrs(id, addrs, pstore.PermanentAddrTTL)
}
// TestConnectednessCorrect starts a few networks, connects a few
// and tests Connectedness value is correct.
func TestConnectednessCorrect(t *testing.T) {
......@@ -18,13 +39,13 @@ func TestConnectednessCorrect(t *testing.T) {
nets := make([]inet.Network, 4)
for i := 0; i < 4; i++ {
nets[i] = testutil.GenSwarmNetwork(t, ctx)
nets[i] = GenSwarmNetwork(t, ctx)
}
// connect 0-1, 0-2, 0-3, 1-2, 2-3
dial := func(a, b inet.Network) {
testutil.DivulgeAddresses(b, a)
DivulgeAddresses(b, a)
if _, err := a.DialPeer(ctx, b.LocalPeer()); err != nil {
t.Fatalf("Failed to dial: %s", err)
}
......@@ -109,11 +130,11 @@ func TestNetworkOpenStream(t *testing.T) {
nets := make([]inet.Network, 4)
for i := 0; i < 4; i++ {
nets[i] = testutil.GenSwarmNetwork(t, ctx)
nets[i] = GenSwarmNetwork(t, ctx)
}
dial := func(a, b inet.Network) {
testutil.DivulgeAddresses(b, a)
DivulgeAddresses(b, a)
if _, err := a.DialPeer(ctx, b.LocalPeer()); err != nil {
t.Fatalf("Failed to dial: %s", err)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment