module_area_rpc

package
v0.0.0-...-58a2b35 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 13 Imported by: 0

README

RPC接口

一. 接口说明

1. 接口用例
curl --request POST --url http://127.0.0.1:2081/rpc --header 'password: testp'  --header 'user: test' --data '{"method":"waitautonomyfinish"}'
url

http://127.0.0.1:2081/rpc

method

POST

Content-Type

application/json

header参数
参数
user test
password testp
2.返回结构
{
  "jsonrpc": "2.0",
  "code": 2000,
  "result": {
  }
}
3.错误码
参数 描述
Success 2000 成功
NoMethod 4001 没有这个方法
TypeWrong 5001 参数类型错误
NoField 5002 缺少参数
Nomarl 5003 一般错误,请看错误提示信息
Timeout 5004 超时
Exist 5005 已经存在
FailPwd 5006 密码错误
NotExist 5007 不存在

二. 接口明细

1. 等待网络自治完成
请求
{
    "method": "waitautonomyfinish"
}
2. 等待网络自治完成
请求
{
    "method": "waitautonomyfinishvnode"
}
3. 等待网络自治完成
请求
{
    "method": "getnetid"
}
4. 获取本节点虚拟节点地址
请求
{
    "method": "getvnodeid"
}
5. 获取idinfo
请求
{
    "method": "getidinfo"
}
6. 获取NodeSelf
请求
{
    "method": "getnodeself"
}
7. 关闭所有网络连接
请求
{
    "method": "closenet"
}
8. 重新链接网络
请求
{
    "method": "reconnectnet"
}
9. 检查是否在线
请求
{
    "method": "checkonline"
}
10. 添加一个地址到白名单
请求
{
    "method": "addwhitelist",
    "params": {
        "address": "54oeEHBNB9yAnw6xN8YKTdv2BHrMseyRHEH24gt5Wt7n"
    }
}
11. 删除一个地址到白名单
请求
{
    "method": "removewhitelist",
    "params": {
        "address": "54oeEHBNB9yAnw6xN8YKTdv2BHrMseyRHEH24gt5Wt7n"
    }
}
12. 添加一个连接
请求
{
    "method": "addconnect",
    "params": {
        "ip": "127.0.0.1",
        "port": 2082
    }
}
13. 搜索磁力节点网络地址
请求
{
    "method": "searchnetaddr",
    "params": {
        "address": "54oeEHBNB9yAnw6xN8YKTdv2BHrMseyRHEH24gt5Wt7n"
    }
}
14. 搜索磁力虚拟节点网络地址
请求
{
    "method": "searchnetaddrvnode",
    "params": {
        "address": "OMko7LyxGwZFwZ2eTR/mvbnenU+5SUhnt5AvUO45hB8="
    }
}
15. 获取所有连接
请求
{
    "method": "networkinfolist"
}
16. 发送一个新的广播消息
请求
{
    "method": "sendmulticastmsg",
    "params":{
        "content":"hello world"
    }
}
17. 发送一个新的查找超级节点消息
请求
{
    "method": "sendsearchsupermsg",
    "params": {
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello"
    }
}
18. 发送一个新的查找超级节点消息
请求
{
    "method": "sendsearchsupermsgwaitrequest",
    "params": {
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello"
    }
}
19. 发送一个新消息
请求
{
    "method": "sendp2pmsg",
    "params": {
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello"
    }
}
20. 给指定节点发送一个消息
请求
{
    "method": "sendp2pmsgwaitrequest",
    "params": {
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello world"
    }
}
21. 发送一个加密消息,包括消息头也加密
请求
{
    "method": "sendp2pmsghe",
    "params": {
        "recv_address": "7DcSuUeVWGLGr4RG2zVS7iR8rS4uqSeHtouJh955zEAz",
        "content": "hello world"
    }
}
22. 发送一个加密消息,包括消息头也加密
请求
{
    "method": "sendp2pmsghewaitrequest",
    "params": {
        "recv_address": "7DcSuUeVWGLGr4RG2zVS7iR8rS4uqSeHtouJh955zEAz",
        "content": "hello world"
    }
}
21. 网络中查询一个逻辑节点地址的真实地址
请求
{
    "method": "searchvnodeid",
    "params": {
        "vnode_address": "7DcSuUeVWGLGr4RG2zVS7iR8rS4uqSeHtouJh955zEAz"
    }
}
22. 发送一个新的查找超级节点消息,可以指定接收端和发送端的代理节点
请求
{
    "method": "sendsearchsupermsgproxy",
    "params": {
        "sender_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello world"
    }
}
23. 发送一个新的查找超级节点消息,可以指定接收端和发送端的代理节点
请求
{
    "method": "sendsearchsupermsgproxywaitrequest",
    "params": {
        "sender_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello world"
    }
}
24. 发送一个新消息,可以指定接收端和发送端的代理节点
请求
{
    "method": "sendp2pmsgproxy",
    "params": {
        "sender_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello world"
    }
}
25. 给指定节点发送一个消息,可以指定接收端和发送端的代理节点
请求
{
    "method": "sendp2pmsgproxywaitrequest",
    "params": {
        "sender_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello world"
    }
}
26. 发送一个加密消息,包括消息头也加密,可以指定接收端和发送端的代理节点
请求
{
    "method": "sendp2pmsgheproxy",
    "params": {
        "sender_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello world"
    }
}
27. 发送一个加密消息,包括消息头也加密,可以指定接收端和发送端的代理节点
请求
{
    "method": "sendp2pmsgheproxywaitrequest",
    "params": {
        "sender_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "recv_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "content": "hello world"
    }
}
28. 根据目标ip地址及端口添加到白名单
请求
{
    "method": "addaddrwhitelist",
    "params": {
        "ip": "127.0.0.1",
        "port": "19990"
    }
}
29. 设置区域上帝地址信息
请求
{
    "method": "setareagodaddr",
    "params": {
        "ip": "127.0.0.1",
        "port": "19990"
    }
}
30. 搜索磁力节点网络地址,可以指定接收端和发送端的代理节点
请求
{
    "method": "searchnetaddrproxy",
    "params": {
        "address": "OMko7LyxGwZFwZ2eTR/mvbnenU+5SUhnt5AvUO45hB8=",
        "recv_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm",
        "sender_proxy_address": "FtZdqgsQst2YFqQyMC7qF2WmtUuWiMxoFYofAv2sCWNm"
    }
}
31. 根据目标节点,返回排序后的虚拟节点地址列表
请求
{
    "method": "findnearvnodessearchvnode",
    "params": {
        "address": "OMko7LyxGwZFwZ2eTR/mvbnenU+5SUhnt5AvUO45hB8=",
        "include_self": true,
        "include_index0": true
    }
}
32. 得到所有连接的节点信息,不包括本节点
请求
{
    "method": "getallnodes"
}
32. 获取设备机器Id
请求
{
    "method": "getmachineid"
}

Documentation

Index

Constants

View Source
const (
	DEFAULT_TIMEOUT      = 6 * time.Second
	MSGID_TEST_MULTICAST = 70000 + iota
	MSGID_TEST_SEARCH_SUPER
	MSGID_TEST_SEARCH_SUPER_WAIT
	MSGID_TEST_SEARCH_SUPER_WAIT_RECV
	MSGID_TEST_P2P
	MSGID_TEST_P2P_WAIT
	MSGID_TEST_P2P_WAIT_RECV
	MSGID_TEST_P2P_HE
	MSGID_TEST_P2P_HE_WAIT
	MSGID_TEST_P2P_HE_WAIT_RECV
	MSGID_TEST_P2P_PROXY
	MSGID_TEST_P2P_PROXY_WAIT
	MSGID_TEST_P2P_PROXY_WAIT_RECV
	MSGID_TEST_P2P_HE_PROXY
	MSGID_TEST_P2P_HE_PROXY_WAIT
	MSGID_TEST_P2P_HE_PROXY_WAIT_RECV
	MSGID_TEST_SEARCH_SUPER_PROXY
	MSGID_TEST_SEARCH_SUPER_PROXY_WAIT
	MSGID_TEST_SEARCH_SUPER_PROXY_WAIT_RECV
)

用于测试

Variables

View Source
var MSGIDStr = make(map[uint64]string)

Functions

func AddAddrWhiteList

func AddAddrWhiteList(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 根据目标ip地址及端口添加到白名单

func AddConnect

func AddConnect(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

添加一个连接

func AddWhiteList

func AddWhiteList(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

添加一个地址到白名单

func CheckOnline

func CheckOnline(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

检查是否在线(链接有没有断开)

func CloseNet

func CloseNet(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

关闭所有网络连接 移动端关闭移动网络切换到wifi网络时调用

func FindNearVnodesSearchVnode

func FindNearVnodesSearchVnode(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 根据目标节点,返回排序后的虚拟节点地址列表

func GetAllConnectNode

func GetAllConnectNode(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

*获取本节点所有连接节点

func GetAllNodes

func GetAllNodes(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 得到所有连接的节点信息,不包括本节点

func GetIdInfo

func GetIdInfo(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

获取idinfo

func GetMachineID

func GetMachineID(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 获取设备机器Id

func GetNetId

func GetNetId(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

获取本节点地址

func GetNetworkInfo

func GetNetworkInfo(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

获取所有网络连接

func GetNodeSelf

func GetNodeSelf(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

获取NodeSelf

func GetVnodeId

func GetVnodeId(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

获取本节点虚拟节点地址

func ReconnectNet

func ReconnectNet(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

重新链接网络

func RegisterLibp2pareaRPC

func RegisterLibp2pareaRPC()

func RegisterTestMsg

func RegisterTestMsg()

注册测试 MSGID

func RemoveWhiteList

func RemoveWhiteList(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

删除一个地址到白名单

func SearchNetAddr

func SearchNetAddr(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

搜索磁力节点网络地址

func SearchNetAddrProxy

func SearchNetAddrProxy(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 搜索磁力节点网络地址,可以指定发送端的代理节点

func SearchNetAddrVnode

func SearchNetAddrVnode(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

搜索磁力虚拟节点网络地址

func SearchVnodeId

func SearchVnodeId(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

网络中查询一个逻辑节点地址的真实地址

func SendMulticastMsg

func SendMulticastMsg(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

发送一个新的广播消息

func SendP2pMsg

func SendP2pMsg(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

发送一个新消息 @return *Message 返回的消息 @return bool 是否发送成功 @return bool 消息是发给自己

func SendP2pMsgHE

func SendP2pMsgHE(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

发送一个加密消息,包括消息头也加密 @return *Message 返回的消息 @return bool 是否发送成功 @return bool 消息是发给自己

func SendP2pMsgHEProxy

func SendP2pMsgHEProxy(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 发送一个加密消息,包括消息头也加密,可以指定接收端和发送端的代理节点 * @return *Message 返回的消息 * @return bool 是否发送成功 * @return bool 消息是发给自己

func SendP2pMsgHEProxyWaitRequest

func SendP2pMsgHEProxyWaitRequest(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 发送一个加密消息,包括消息头也加密,可以指定接收端和发送端的代理节点 * @return *Message 返回的消息 * @return bool 是否发送成功 * @return bool 消息是发给自己

func SendP2pMsgHEWaitRequest

func SendP2pMsgHEWaitRequest(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

发送一个加密消息,包括消息头也加密 @return *Message 返回的消息 @return bool 是否发送成功 @return bool 消息是发给自己

func SendP2pMsgProxy

func SendP2pMsgProxy(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 发送一个新消息,可以指定接收端和发送端的代理节点 * @return *Message 返回的消息 * @return bool 是否发送成功 * @return bool 消息是发给自己

func SendP2pMsgProxyWaitRequest

func SendP2pMsgProxyWaitRequest(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 给指定节点发送一个消息,可以指定接收端和发送端的代理节点 * @return *[]byte 返回的内容 * @return bool 是否发送成功 * @return bool 消息是发给自己

func SendP2pMsgWaitRequest

func SendP2pMsgWaitRequest(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

给指定节点发送一个消息 @return *[]byte 返回的内容 @return bool 是否发送成功 @return bool 消息是发给自己

func SendSearchSuperMsg

func SendSearchSuperMsg(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

发送一个新的查找超级节点消息

func SendSearchSuperMsgProxy

func SendSearchSuperMsgProxy(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 发送一个新的查找超级节点消息,可以指定接收端和发送端的代理节点

func SendSearchSuperMsgProxyWaitRequest

func SendSearchSuperMsgProxyWaitRequest(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 发送一个新的查找超级节点消息,可以指定接收端和发送端的代理节点

func SendSearchSuperMsgWaitRequest

func SendSearchSuperMsgWaitRequest(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

发送一个新的查找超级节点消息

func SetAreaGodAddr

func SetAreaGodAddr(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

* 设置区域上帝地址信息

func Start

func Start(area *libp2parea.Area)

func WaitAutonomyFinish

func WaitAutonomyFinish(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

等待网络自治完成

func WaitAutonomyFinishVnode

func WaitAutonomyFinishVnode(rj *model.RpcJson, w http.ResponseWriter, r *http.Request) (res []byte, err error)

等待虚拟节点网络自治完成

Types

This section is empty.

Jump to

Keyboard shortcuts

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