relay-demo

command
v0.0.0-...-e899ace Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

relay-demo examples and turorials

relay-demo是用于演示中继功能的例子,是指在B节点的中继下,使得原来不能直接通信的A节点与C节点通过B节点可以通信,且后续所有通信流量都经过B节点。 A <---> B <---> C

Step 0

准备Go语言环境,安装相关包。 通过build命令来编译源码文件,完成后按照顺序启动B,A,C三个节点。 go build main.go 如果条件允许,可以搭建docker环境,利用bridge可以做到A和C两个节点网络隔离。

Step 1

先使用-c 2参数启动中继节点B,命令如下: $ ./main -c 2

此时,中继节点B已启动,

This node's multiaddresses:
 - /ip4/127.0.0.1/tcp/51140
 - /ip4/192.168.199.115/tcp/51140
 - /ip4/192.168.192.160/tcp/51140

Run './main -c 1 -d /ip4/{ip}/tcp/51140/p2p/Qmbp1hxgcaLpBQAhZw4965jWKPtSMjrMHUWci5v6e8aeZF' on another console.

I am relay

启动后提示信息如上所述,给出了绑定的所有网卡的地址信息,以及A节点的启动命令 ./main -c 1 -d /ip4/{ip}/tcp/51140/p2p/Qmbp1hxgcaLpBQAhZw4965jWKPtSMjrMHUWci5v6e8aeZF,后续根据需要选择合适的网卡地址信息以替换上述命令的{ip}部分。

Step 2

启动A节点,这里直接使用127.0.0.1地址测试,替换{ip}部分后命令如下,./main -c 1 -d /ip4/127.0.0.1/tcp/51140/p2p/Qmbp1hxgcaLpBQAhZw4965jWKPtSMjrMHUWci5v6e8aeZF

此时,中继节点A已启动,

This node's multiaddresses:
 - /ip4/127.0.0.1/tcp/51226
 - /ip4/192.168.199.115/tcp/51226
 - /ip4/192.168.192.160/tcp/51226

Run './main -c 3 -d /ip4/127.0.0.1/tcp/51140/p2p/Qmbp1hxgcaLpBQAhZw4965jWKPtSMjrMHUWci5v6e8aeZF/p2p-circuit/p2p/QmZKZoyNsomMyDmeBcZJLC6pX2MhVahWyndGZydoKrCFJC' on another console.

启动后提示信息如上所述,给出了绑定的所有网卡的地址信息,这部分不用关心, 注意C节点的启动命令 ./main -c 3 -d /ip4/127.0.0.1/tcp/51140/p2p/Qmbp1hxgcaLpBQAhZw4965jWKPtSMjrMHUWci5v6e8aeZF/p2p-circuit/p2p/QmZKZoyNsomMyDmeBcZJLC6pX2MhVahWyndGZydoKrCFJC,后续可能需要选择合适的网卡地址信息以替换上述命令的127.0.0.1部分,具体以C能连接到B的相应网卡地址信息为准。

Step 3

启动C节点,这里直接使用127.0.0.1地址测试,命令如下, ./main -c 3 -d /ip4/127.0.0.1/tcp/51140/p2p/Qmbp1hxgcaLpBQAhZw4965jWKPtSMjrMHUWci5v6e8aeZF/p2p-circuit/p2p/QmZKZoyNsomMyDmeBcZJLC6pX2MhVahWyndGZydoKrCFJC

至此,A与C的连接建立,双方可以互相在console中通信。

Documentation

Overview

* * The MIT License (MIT) * * Copyright (c) 2014 Juan Batiz-Benet * * 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. * * This program demonstrate a application using p2p relay protocol. * With relay Protocol, node behind NAT can also join the network. * * this file describes how dose the demo work

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL