提交 2f17a67c 作者: Tom Swindell 提交者: Łukasz Magiera

Experimental corenet application support.

License: MIT
Signed-off-by: 's avatarTom Swindell <t.swindell@rubyx.co.uk>
上级 20dae521
package commands
import (
cmds "github.com/ipfs/go-ipfs/commands"
)
var ExpCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Experimental commands",
ShortDescription: `'ipfs exp' groups experimental features that are subject to change or removal at any time.`,
},
Subcommands: map[string]*cmds.Command{
"corenet": CorenetCmd,
},
}
...@@ -47,6 +47,7 @@ ADVANCED COMMANDS ...@@ -47,6 +47,7 @@ ADVANCED COMMANDS
pin Pin objects to local storage pin Pin objects to local storage
repo Manipulate the IPFS repository repo Manipulate the IPFS repository
stats Various operational stats stats Various operational stats
exp Experimental commands
filestore Manage the filestore (experimental) filestore Manage the filestore (experimental)
NETWORK COMMANDS NETWORK COMMANDS
......
...@@ -11,7 +11,13 @@ import ( ...@@ -11,7 +11,13 @@ import (
peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer" peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
) )
type Listener interface {
Accept() (net.Stream, error)
Close() error
}
type ipfsListener struct { type ipfsListener struct {
node *core.IpfsNode
conCh chan net.Stream conCh chan net.Stream
proto pro.ID proto pro.ID
ctx context.Context ctx context.Context
...@@ -29,7 +35,7 @@ func (il *ipfsListener) Accept() (net.Stream, error) { ...@@ -29,7 +35,7 @@ func (il *ipfsListener) Accept() (net.Stream, error) {
func (il *ipfsListener) Close() error { func (il *ipfsListener) Close() error {
il.cancel() il.cancel()
// TODO: unregister handler from peerhost il.node.PeerHost.RemoveStreamHandler(il.proto)
return nil return nil
} }
...@@ -37,6 +43,7 @@ func Listen(nd *core.IpfsNode, protocol string) (*ipfsListener, error) { ...@@ -37,6 +43,7 @@ func Listen(nd *core.IpfsNode, protocol string) (*ipfsListener, error) {
ctx, cancel := context.WithCancel(nd.Context()) ctx, cancel := context.WithCancel(nd.Context())
list := &ipfsListener{ list := &ipfsListener{
node: nd,
proto: pro.ID(protocol), proto: pro.ID(protocol),
conCh: make(chan net.Stream), conCh: make(chan net.Stream),
ctx: ctx, ctx: ctx,
......
#!/bin/sh
test_description="Test experimental corenet commands"
. lib/test-lib.sh
# start iptb + wait for peering
test_expect_success 'init iptb' '
iptb init -n 2 --bootstrap=none --port=0
'
test_expect_success 'generate test data' '
echo "ABCDEF" > corenet0.bin &&
echo "012345" > corenet1.bin
'
startup_cluster 2
test_expect_success 'peer ids' '
PEERID_0=$(iptb get id 0) &&
PEERID_1=$(iptb get id 1)
'
# netcat (nc) is needed for the following tests
test_expect_success "nc is available" '
type nc >/dev/null
'
test_expect_success 'start ipfs listener' '
ipfsi 0 exp corenet listen corenet-test /ip4/127.0.0.1/tcp/10001 2>&1 > listener-stdouterr.log
'
test_expect_success 'Test server to client communications' '
dd if=corenet0.bin | nc -l 127.0.0.1 10001 &
NC_SERVER_PID=$!
ipfsi 1 exp corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10002 2>&1 > dialer-stdouterr.log &&
nc -v 127.0.0.1 10002 | dd of=client.out &&
wait $NC_SERVER_PID
'
test_expect_success 'Test server to client communications' '
nc -l 127.0.0.1 10001 | dd of=server.out &
NC_SERVER_PID=$!
ipfsi 1 exp corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10002 2>&1 > dialer-stdouterr.log &&
dd of=corenet1.bin | nc -v 127.0.0.1 10002 &&
wait $NC_SERVER_PID
'
test_expect_success 'server to client output looks good' '
test_cmp client.out corenet0.bin
'
test_expect_success 'client to server output looks good' '
test_cmp server.out corenet1.bin
'
test_expect_success 'stop iptb' '
iptb stop
'
test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论