Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
1a53ad77
Commit
1a53ad77
authored
8 years ago
by
Jeromy
Browse files
Options
Download
Email Patches
Plain Diff
extract host interface
parent
9910e6a7
master
2018-Q4-OKR
docs-improvements
feat/p2p-multiaddr
feat/pnet/working3
feat/protobuf
feat/relay-integrate
feat/udp
feature/standardize-readme
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-jccl6u
gx/update-nza0mn
jenkinsfile
kevina/fix-go-vet
multistream-ping
punching
revert-276-update-go-detect-race
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
v5.0.15
v5.0.14
v5.0.13
v5.0.12
v5.0.11
v5.0.10
v5.0.9
v5.0.8
v5.0.7
v5.0.6
v5.0.5
v5.0.4
v5.0.3
v5.0.2
v5.0.1
v5.0.0
v4.5.5
v4.5.4
v4.5.3
v4.5.2
v4.5.1
v4.5.0
v4.4.5
v4.4.4
v4.4.3
v4.4.2
v4.4.1
v4.4.0
v4.3.12
v4.3.11
v4.3.10
v4.3.9
v4.3.8
v4.3.7
v4.3.6
v4.3.5
v4.3.4
v4.3.3
v4.3.2
v4.3.1
v4.3.0
v4.2.0
v4.1.0
v4.0.4
v4.0.3
v4.0.2
v4.0.1
v4.0.0
No related merge requests found
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
examples/hosts/main.go
+1
-1
examples/hosts/main.go
p2p/discovery/mdns.go
+1
-1
p2p/discovery/mdns.go
p2p/discovery/mdns_test.go
+1
-1
p2p/discovery/mdns_test.go
p2p/host/basic/basic_host_test.go
+1
-1
p2p/host/basic/basic_host_test.go
p2p/host/host.go
+0
-70
p2p/host/host.go
p2p/host/match.go
+0
-36
p2p/host/match.go
p2p/host/match_test.go
+0
-33
p2p/host/match_test.go
p2p/host/routed/routed.go
+1
-1
p2p/host/routed/routed.go
p2p/net/mock/interface.go
+1
-1
p2p/net/mock/interface.go
p2p/net/mock/mock_net.go
+1
-1
p2p/net/mock/mock_net.go
p2p/protocol/identify/id.go
+1
-1
p2p/protocol/identify/id.go
p2p/protocol/identify/id_test.go
+2
-2
p2p/protocol/identify/id_test.go
p2p/protocol/ping/ping.go
+1
-1
p2p/protocol/ping/ping.go
p2p/protocol/relay/relay.go
+1
-1
p2p/protocol/relay/relay.go
p2p/test/backpressure/backpressure_test.go
+1
-1
p2p/test/backpressure/backpressure_test.go
p2p/test/reconnects/reconnect_test.go
+1
-1
p2p/test/reconnects/reconnect_test.go
package.json
+6
-0
package.json
with
20 additions
and
153 deletions
+20
-153
examples/hosts/main.go
View file @
1a53ad77
...
...
@@ -8,9 +8,9 @@ import (
"log"
"strings"
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
net
"github.com/libp2p/go-libp2p-net"
host
"github.com/libp2p/go-libp2p/p2p/host"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
swarm
"github.com/libp2p/go-libp2p/p2p/net/swarm"
...
...
This diff is collapsed.
Click to expand it.
p2p/discovery/mdns.go
View file @
1a53ad77
...
...
@@ -15,7 +15,7 @@ import (
logging
"github.com/ipfs/go-log"
ma
"github.com/jbenet/go-multiaddr"
manet
"github.com/jbenet/go-multiaddr-net"
"github.com/libp2p/go-libp2p
/p2p/
host"
"github.com/libp2p/go-libp2p
-
host"
"github.com/whyrusleeping/mdns"
)
...
...
This diff is collapsed.
Click to expand it.
p2p/discovery/mdns_test.go
View file @
1a53ad77
...
...
@@ -5,7 +5,7 @@ import (
"testing"
"time"
host
"github.com/libp2p/go-libp2p
/p2p/
host"
host
"github.com/libp2p/go-libp2p
-
host"
netutil
"github.com/libp2p/go-libp2p/p2p/test/util"
pstore
"github.com/ipfs/go-libp2p-peerstore"
...
...
This diff is collapsed.
Click to expand it.
p2p/host/basic/basic_host_test.go
View file @
1a53ad77
...
...
@@ -7,9 +7,9 @@ import (
"testing"
"time"
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
protocol
"github.com/libp2p/go-libp2p-protocol"
host
"github.com/libp2p/go-libp2p/p2p/host"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
)
...
...
This diff is collapsed.
Click to expand it.
p2p/host/host.go
deleted
100644 → 0
View file @
9910e6a7
package
host
import
(
"context"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
logging
"github.com/ipfs/go-log"
ma
"github.com/jbenet/go-multiaddr"
metrics
"github.com/libp2p/go-libp2p-metrics"
inet
"github.com/libp2p/go-libp2p-net"
protocol
"github.com/libp2p/go-libp2p-protocol"
msmux
"github.com/whyrusleeping/go-multistream"
)
var
log
=
logging
.
Logger
(
"github.com/libp2p/go-libp2p/p2p/host"
)
// Host is an object participating in a p2p network, which
// implements protocols or provides services. It handles
// requests like a Server, and issues requests like a Client.
// It is called Host because it is both Server and Client (and Peer
// may be confusing).
type
Host
interface
{
// ID returns the (local) peer.ID associated with this Host
ID
()
peer
.
ID
// Peerstore returns the Host's repository of Peer Addresses and Keys.
Peerstore
()
pstore
.
Peerstore
// Returns the listen addresses of the Host
Addrs
()
[]
ma
.
Multiaddr
// Networks returns the Network interface of the Host
Network
()
inet
.
Network
// Mux returns the Mux multiplexing incoming streams to protocol handlers
Mux
()
*
msmux
.
MultistreamMuxer
// Connect ensures there is a connection between this host and the peer with
// given peer.ID. Connect will absorb the addresses in pi into its internal
// peerstore. If there is not an active connection, Connect will issue a
// h.Network.Dial, and block until a connection is open, or an error is
// returned. // TODO: Relay + NAT.
Connect
(
ctx
context
.
Context
,
pi
pstore
.
PeerInfo
)
error
// SetStreamHandler sets the protocol handler on the Host's Mux.
// This is equivalent to:
// host.Mux().SetHandler(proto, handler)
// (Threadsafe)
SetStreamHandler
(
pid
protocol
.
ID
,
handler
inet
.
StreamHandler
)
// SetStreamHandlerMatch sets the protocol handler on the Host's Mux
// using a matching function for protocol selection.
SetStreamHandlerMatch
(
protocol
.
ID
,
func
(
string
)
bool
,
inet
.
StreamHandler
)
// RemoveStreamHandler removes a handler on the mux that was set by
// SetStreamHandler
RemoveStreamHandler
(
pid
protocol
.
ID
)
// NewStream opens a new stream to given peer p, and writes a p2p/protocol
// header with given protocol.ID. If there is no connection to p, attempts
// to create one. If ProtocolID is "", writes no header.
// (Threadsafe)
NewStream
(
ctx
context
.
Context
,
p
peer
.
ID
,
pids
...
protocol
.
ID
)
(
inet
.
Stream
,
error
)
// Close shuts down the host, its Network, and services.
Close
()
error
GetBandwidthReporter
()
metrics
.
Reporter
}
This diff is collapsed.
Click to expand it.
p2p/host/match.go
deleted
100644 → 0
View file @
9910e6a7
package
host
import
(
"github.com/libp2p/go-libp2p-protocol"
"strings"
semver
"github.com/coreos/go-semver/semver"
)
func
MultistreamSemverMatcher
(
base
protocol
.
ID
)
(
func
(
string
)
bool
,
error
)
{
parts
:=
strings
.
Split
(
string
(
base
),
"/"
)
vers
,
err
:=
semver
.
NewVersion
(
parts
[
len
(
parts
)
-
1
])
if
err
!=
nil
{
return
nil
,
err
}
return
func
(
check
string
)
bool
{
chparts
:=
strings
.
Split
(
check
,
"/"
)
if
len
(
chparts
)
!=
len
(
parts
)
{
return
false
}
for
i
,
v
:=
range
chparts
[
:
len
(
chparts
)
-
1
]
{
if
parts
[
i
]
!=
v
{
return
false
}
}
chvers
,
err
:=
semver
.
NewVersion
(
chparts
[
len
(
chparts
)
-
1
])
if
err
!=
nil
{
return
false
}
return
vers
.
Major
==
chvers
.
Major
&&
vers
.
Minor
>=
chvers
.
Minor
},
nil
}
This diff is collapsed.
Click to expand it.
p2p/host/match_test.go
deleted
100644 → 0
View file @
9910e6a7
package
host
import
(
"testing"
)
func
TestSemverMatching
(
t
*
testing
.
T
)
{
m
,
err
:=
MultistreamSemverMatcher
(
"/testing/4.3.5"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cases
:=
map
[
string
]
bool
{
"/testing/4.3.0"
:
true
,
"/testing/4.3.7"
:
true
,
"/testing/4.3.5"
:
true
,
"/testing/4.2.7"
:
true
,
"/testing/4.0.0"
:
true
,
"/testing/5.0.0"
:
false
,
"/cars/dogs/4.3.5"
:
false
,
"/foo/1.0.0"
:
false
,
""
:
false
,
"dogs"
:
false
,
"/foo"
:
false
,
"/foo/1.1.1.1"
:
false
,
}
for
p
,
ok
:=
range
cases
{
if
m
(
p
)
!=
ok
{
t
.
Fatalf
(
"expected %s to be %t"
,
p
,
ok
)
}
}
}
This diff is collapsed.
Click to expand it.
p2p/host/routed/routed.go
View file @
1a53ad77
...
...
@@ -5,7 +5,7 @@ import (
"fmt"
"time"
host
"github.com/libp2p/go-libp2p
/p2p/
host"
host
"github.com/libp2p/go-libp2p
-
host"
lgbl
"github.com/ipfs/go-libp2p-loggables"
peer
"github.com/ipfs/go-libp2p-peer"
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/interface.go
View file @
1a53ad77
...
...
@@ -10,7 +10,7 @@ import (
"io"
"time"
host
"github.com/libp2p/go-libp2p
/p2p/
host"
host
"github.com/libp2p/go-libp2p
-
host"
ic
"github.com/ipfs/go-libp2p-crypto"
peer
"github.com/ipfs/go-libp2p-peer"
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_net.go
View file @
1a53ad77
...
...
@@ -6,7 +6,7 @@ import (
"sort"
"sync"
host
"github.com/libp2p/go-libp2p
/p2p/
host"
host
"github.com/libp2p/go-libp2p
-
host"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
p2putil
"github.com/libp2p/go-libp2p/p2p/test/util"
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/identify/id.go
View file @
1a53ad77
...
...
@@ -5,7 +5,6 @@ import (
"strings"
"sync"
host
"github.com/libp2p/go-libp2p/p2p/host"
pb
"github.com/libp2p/go-libp2p/p2p/protocol/identify/pb"
semver
"github.com/coreos/go-semver/semver"
...
...
@@ -16,6 +15,7 @@ import (
pstore
"github.com/ipfs/go-libp2p-peerstore"
logging
"github.com/ipfs/go-log"
ma
"github.com/jbenet/go-multiaddr"
host
"github.com/libp2p/go-libp2p-host"
mstream
"github.com/libp2p/go-libp2p-metrics/stream"
inet
"github.com/libp2p/go-libp2p-net"
msmux
"github.com/whyrusleeping/go-multistream"
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/identify/id_test.go
View file @
1a53ad77
package
identify_test
import
(
"context"
"testing"
"time"
ic
"github.com/ipfs/go-libp2p-crypto"
peer
"github.com/ipfs/go-libp2p-peer"
host
"github.com/libp2p/go-libp2p/p2p/host"
identify
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
"context"
ma
"github.com/jbenet/go-multiaddr"
host
"github.com/libp2p/go-libp2p-host"
)
func
subtestIDService
(
t
*
testing
.
T
,
postDialWait
time
.
Duration
)
{
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/ping/ping.go
View file @
1a53ad77
...
...
@@ -10,8 +10,8 @@ import (
u
"github.com/ipfs/go-ipfs-util"
peer
"github.com/ipfs/go-libp2p-peer"
logging
"github.com/ipfs/go-log"
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
host
"github.com/libp2p/go-libp2p/p2p/host"
)
var
log
=
logging
.
Logger
(
"ping"
)
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/relay/relay.go
View file @
1a53ad77
...
...
@@ -6,7 +6,7 @@ import (
"io"
"time"
host
"github.com/libp2p/go-libp2p
/p2p/
host"
host
"github.com/libp2p/go-libp2p
-
host"
peer
"github.com/ipfs/go-libp2p-peer"
logging
"github.com/ipfs/go-log"
...
...
This diff is collapsed.
Click to expand it.
p2p/test/backpressure/backpressure_test.go
View file @
1a53ad77
...
...
@@ -10,9 +10,9 @@ import (
u
"github.com/ipfs/go-ipfs-util"
peer
"github.com/ipfs/go-libp2p-peer"
logging
"github.com/ipfs/go-log"
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
protocol
"github.com/libp2p/go-libp2p-protocol"
host
"github.com/libp2p/go-libp2p/p2p/host"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
)
...
...
This diff is collapsed.
Click to expand it.
p2p/test/reconnects/reconnect_test.go
View file @
1a53ad77
...
...
@@ -11,9 +11,9 @@ import (
u
"github.com/ipfs/go-ipfs-util"
logging
"github.com/ipfs/go-log"
ps
"github.com/jbenet/go-peerstream"
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
protocol
"github.com/libp2p/go-libp2p-protocol"
host
"github.com/libp2p/go-libp2p/p2p/host"
swarm
"github.com/libp2p/go-libp2p/p2p/net/swarm"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
)
...
...
This diff is collapsed.
Click to expand it.
package.json
View file @
1a53ad77
...
...
@@ -236,6 +236,12 @@
"hash"
:
"QmRxzoGdQaN6HYyqWnT82NnLLHBAZbTUvxPEfTBTjU7KCn"
,
"name"
:
"go-libp2p-interface-conn"
,
"version"
:
"0.1.0"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmaAyA9QMVdzCYHv7QJnKu4Dzk4zfnFrHw9itzP9kEUKYW"
,
"name"
:
"go-libp2p-host"
,
"version"
:
"1.0.0"
}
],
"gxVersion"
:
"0.4.0"
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help