mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2024-12-28 23:50:12 +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:
|
||||
- linux
|
||||
- osx
|
||||
- linux
|
||||
- osx
|
||||
|
||||
language: go
|
||||
|
||||
@ -9,12 +9,16 @@ go:
|
||||
|
||||
install: true
|
||||
|
||||
before_install:
|
||||
- make deps
|
||||
|
||||
script:
|
||||
- make deps
|
||||
- gx-go rewrite
|
||||
- go get github.com/mattn/goveralls
|
||||
- goveralls -service=travis-ci
|
||||
- go vet
|
||||
- $GOPATH/bin/goveralls -service="travis-ci"
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $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
|
||||
|
||||
gx:
|
||||
go get -u github.com/whyrusleeping/gx
|
||||
go get -u github.com/whyrusleeping/gx-go
|
||||
go get github.com/whyrusleeping/gx
|
||||
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-go rewrite
|
||||
go get -t ./...
|
||||
|
||||
publish:
|
||||
gx-go rewrite --undo
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
# 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/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)
|
||||
[![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)
|
||||
[![Build Status](https://travis-ci.org/ipfs/go-libp2p-peerstore.svg?branch=master)](https://travis-ci.org/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/libp2p/go-libp2p-peerstore/badge.svg?branch=master)](https://coveralls.io/github/libp2p/go-libp2p-peerstore?branch=master)
|
||||
[![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.
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
package peerstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
peer "github.com/ipfs/go-libp2p-peer"
|
||||
addr "github.com/ipfs/go-libp2p-peerstore/addr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
"golang.org/x/net/context"
|
||||
addr "github.com/libp2p/go-libp2p-peerstore/addr"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -40,7 +40,7 @@ func testHas(t *testing.T, exp, act []ma.Multiaddr) {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func NewMetrics() Metrics {
|
||||
func NewMetrics() *metrics {
|
||||
return &metrics{
|
||||
latmap: make(map[peer.ID]time.Duration),
|
||||
}
|
||||
|
10
package.json
10
package.json
@ -1,10 +1,10 @@
|
||||
{
|
||||
"author": "whyrusleeping",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ipfs/go-libp2p-peerstore"
|
||||
"url": "https://github.com/libp2p/go-libp2p-peerstore"
|
||||
},
|
||||
"gx": {
|
||||
"dvcsimport": "github.com/ipfs/go-libp2p-peerstore"
|
||||
"dvcsimport": "github.com/libp2p/go-libp2p-peerstore"
|
||||
},
|
||||
"gxDependencies": [
|
||||
{
|
||||
@ -25,12 +25,6 @@
|
||||
"name": "go-multiaddr",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"author": "whyrusleeping",
|
||||
"hash": "QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt",
|
||||
"name": "go-net",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"author": "whyrusleeping",
|
||||
"hash": "QmUusaX99BZoELh7dmPgirqRQ1FAmMnmnBn3oiqDFGBUSc",
|
||||
|
10
peerstore.go
10
peerstore.go
@ -1,6 +1,7 @@
|
||||
package peerstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
@ -13,7 +14,6 @@ import (
|
||||
"github.com/ipfs/go-libp2p-peer"
|
||||
logging "github.com/ipfs/go-log"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("peerstore")
|
||||
@ -163,8 +163,8 @@ func (kb *keybook) AddPrivKey(p peer.ID, sk ic.PrivKey) error {
|
||||
}
|
||||
|
||||
type peerstore struct {
|
||||
keybook
|
||||
metrics
|
||||
*keybook
|
||||
*metrics
|
||||
AddrManager
|
||||
|
||||
// store other data, like versions
|
||||
@ -180,8 +180,8 @@ type peerstore struct {
|
||||
// NewPeerstore creates a threadsafe collection of peers.
|
||||
func NewPeerstore() Peerstore {
|
||||
return &peerstore{
|
||||
keybook: *newKeybook(),
|
||||
metrics: *(NewMetrics()).(*metrics),
|
||||
keybook: newKeybook(),
|
||||
metrics: NewMetrics(),
|
||||
AddrManager: AddrManager{},
|
||||
//ds: dssync.MutexWrap(ds.NewMapDatastore()),
|
||||
ds: make(map[string]interface{}),
|
||||
|
@ -1,6 +1,7 @@
|
||||
package peerstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
@ -9,7 +10,6 @@ import (
|
||||
|
||||
peer "github.com/ipfs/go-libp2p-peer"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func getAddrs(t *testing.T, n int) []ma.Multiaddr {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
@ -8,8 +9,6 @@ import (
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
peer "github.com/ipfs/go-libp2p-peer"
|
||||
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestQueue(t *testing.T) {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
peer "github.com/ipfs/go-libp2p-peer"
|
||||
logging "github.com/ipfs/go-log"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("peerqueue")
|
||||
|
Loading…
Reference in New Issue
Block a user