mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-01-01 00:20:11 +08:00
Merge pull request #9 from libp2p/feat/stdlib-ctx
use context from stdlib
This commit is contained in:
commit
cf69e7912b
16
.travis.yml
16
.travis.yml
@ -1,6 +1,6 @@
|
|||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
- osx
|
- osx
|
||||||
|
|
||||||
language: go
|
language: go
|
||||||
|
|
||||||
@ -9,12 +9,16 @@ go:
|
|||||||
|
|
||||||
install: true
|
install: true
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- make deps
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- make deps
|
- go vet
|
||||||
- gx-go rewrite
|
- $GOPATH/bin/goveralls -service="travis-ci"
|
||||||
- go get github.com/mattn/goveralls
|
|
||||||
- goveralls -service=travis-ci
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- $GOPATH/src/gx
|
- $GOPATH/src/gx
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
17
Makefile
17
Makefile
@ -1,14 +1,17 @@
|
|||||||
test: deps
|
|
||||||
go test -race -v ./...
|
|
||||||
|
|
||||||
export IPFS_API ?= v04x.ipfs.io
|
export IPFS_API ?= v04x.ipfs.io
|
||||||
|
|
||||||
gx:
|
gx:
|
||||||
go get -u github.com/whyrusleeping/gx
|
go get github.com/whyrusleeping/gx
|
||||||
go get -u github.com/whyrusleeping/gx-go
|
go get github.com/whyrusleeping/gx-go
|
||||||
|
|
||||||
deps: gx
|
covertools:
|
||||||
|
go get github.com/mattn/goveralls
|
||||||
|
go get golang.org/x/tools/cmd/cover
|
||||||
|
|
||||||
|
deps: gx covertools
|
||||||
gx --verbose install --global
|
gx --verbose install --global
|
||||||
gx-go rewrite
|
gx-go rewrite
|
||||||
go get -t ./...
|
|
||||||
|
publish:
|
||||||
|
gx-go rewrite --undo
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
# go-libp2p-peer
|
# go-libp2p-peer
|
||||||
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
|
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
|
||||||
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
|
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
|
||||||
[![GoDoc](https://godoc.org/github.com/ipfs/go-libp2p-peer?status.svg)](https://godoc.org/github.com/ipfs/go-libp2p-peerstore)
|
[![GoDoc](https://godoc.org/github.com/libp2p/go-libp2p-peer?status.svg)](https://godoc.org/github.com/libp2p/go-libp2p-peerstore)
|
||||||
[![Coverage Status](https://coveralls.io/repos/github/ipfs/go-libp2p-peerstore/badge.svg?branch=master)](https://coveralls.io/github/ipfs/go-libp2p-peerstore?branch=master)
|
[![Coverage Status](https://coveralls.io/repos/github/libp2p/go-libp2p-peerstore/badge.svg?branch=master)](https://coveralls.io/github/libp2p/go-libp2p-peerstore?branch=master)
|
||||||
[![Build Status](https://travis-ci.org/ipfs/go-libp2p-peerstore.svg?branch=master)](https://travis-ci.org/ipfs/go-libp2p-peerstore)
|
[![Build Status](https://travis-ci.org/libp2p/go-libp2p-peerstore.svg?branch=master)](https://travis-ci.org/libp2p/go-libp2p-peerstore)
|
||||||
|
|
||||||
An object to manage peers, their addresses, and other metadata about them.
|
An object to manage peers, their addresses, and other metadata about them.
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package peerstore
|
package peerstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
peer "github.com/ipfs/go-libp2p-peer"
|
peer "github.com/ipfs/go-libp2p-peer"
|
||||||
addr "github.com/ipfs/go-libp2p-peerstore/addr"
|
|
||||||
ma "github.com/jbenet/go-multiaddr"
|
ma "github.com/jbenet/go-multiaddr"
|
||||||
"golang.org/x/net/context"
|
addr "github.com/libp2p/go-libp2p-peerstore/addr"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -40,7 +40,7 @@ func testHas(t *testing.T, exp, act []ma.Multiaddr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
t.Fatal("expected address %s not found", a)
|
t.Fatalf("expected address %s not found", a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ type metrics struct {
|
|||||||
latmu sync.RWMutex
|
latmu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMetrics() Metrics {
|
func NewMetrics() *metrics {
|
||||||
return &metrics{
|
return &metrics{
|
||||||
latmap: make(map[peer.ID]time.Duration),
|
latmap: make(map[peer.ID]time.Duration),
|
||||||
}
|
}
|
||||||
|
10
package.json
10
package.json
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"author": "whyrusleeping",
|
"author": "whyrusleeping",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/ipfs/go-libp2p-peerstore"
|
"url": "https://github.com/libp2p/go-libp2p-peerstore"
|
||||||
},
|
},
|
||||||
"gx": {
|
"gx": {
|
||||||
"dvcsimport": "github.com/ipfs/go-libp2p-peerstore"
|
"dvcsimport": "github.com/libp2p/go-libp2p-peerstore"
|
||||||
},
|
},
|
||||||
"gxDependencies": [
|
"gxDependencies": [
|
||||||
{
|
{
|
||||||
@ -25,12 +25,6 @@
|
|||||||
"name": "go-multiaddr",
|
"name": "go-multiaddr",
|
||||||
"version": "0.0.0"
|
"version": "0.0.0"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"author": "whyrusleeping",
|
|
||||||
"hash": "QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt",
|
|
||||||
"name": "go-net",
|
|
||||||
"version": "0.0.0"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"author": "whyrusleeping",
|
"author": "whyrusleeping",
|
||||||
"hash": "QmUusaX99BZoELh7dmPgirqRQ1FAmMnmnBn3oiqDFGBUSc",
|
"hash": "QmUusaX99BZoELh7dmPgirqRQ1FAmMnmnBn3oiqDFGBUSc",
|
||||||
|
10
peerstore.go
10
peerstore.go
@ -1,6 +1,7 @@
|
|||||||
package peerstore
|
package peerstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
@ -13,7 +14,6 @@ import (
|
|||||||
"github.com/ipfs/go-libp2p-peer"
|
"github.com/ipfs/go-libp2p-peer"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
ma "github.com/jbenet/go-multiaddr"
|
ma "github.com/jbenet/go-multiaddr"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("peerstore")
|
var log = logging.Logger("peerstore")
|
||||||
@ -163,8 +163,8 @@ func (kb *keybook) AddPrivKey(p peer.ID, sk ic.PrivKey) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type peerstore struct {
|
type peerstore struct {
|
||||||
keybook
|
*keybook
|
||||||
metrics
|
*metrics
|
||||||
AddrManager
|
AddrManager
|
||||||
|
|
||||||
// store other data, like versions
|
// store other data, like versions
|
||||||
@ -180,8 +180,8 @@ type peerstore struct {
|
|||||||
// NewPeerstore creates a threadsafe collection of peers.
|
// NewPeerstore creates a threadsafe collection of peers.
|
||||||
func NewPeerstore() Peerstore {
|
func NewPeerstore() Peerstore {
|
||||||
return &peerstore{
|
return &peerstore{
|
||||||
keybook: *newKeybook(),
|
keybook: newKeybook(),
|
||||||
metrics: *(NewMetrics()).(*metrics),
|
metrics: NewMetrics(),
|
||||||
AddrManager: AddrManager{},
|
AddrManager: AddrManager{},
|
||||||
//ds: dssync.MutexWrap(ds.NewMapDatastore()),
|
//ds: dssync.MutexWrap(ds.NewMapDatastore()),
|
||||||
ds: make(map[string]interface{}),
|
ds: make(map[string]interface{}),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package peerstore
|
package peerstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
@ -9,7 +10,6 @@ import (
|
|||||||
|
|
||||||
peer "github.com/ipfs/go-libp2p-peer"
|
peer "github.com/ipfs/go-libp2p-peer"
|
||||||
ma "github.com/jbenet/go-multiaddr"
|
ma "github.com/jbenet/go-multiaddr"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getAddrs(t *testing.T, n int) []ma.Multiaddr {
|
func getAddrs(t *testing.T, n int) []ma.Multiaddr {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package queue
|
package queue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@ -8,8 +9,6 @@ import (
|
|||||||
|
|
||||||
u "github.com/ipfs/go-ipfs-util"
|
u "github.com/ipfs/go-ipfs-util"
|
||||||
peer "github.com/ipfs/go-libp2p-peer"
|
peer "github.com/ipfs/go-libp2p-peer"
|
||||||
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestQueue(t *testing.T) {
|
func TestQueue(t *testing.T) {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package queue
|
package queue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
peer "github.com/ipfs/go-libp2p-peer"
|
peer "github.com/ipfs/go-libp2p-peer"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
context "golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("peerqueue")
|
var log = logging.Logger("peerqueue")
|
||||||
|
Loading…
Reference in New Issue
Block a user