mirror of
https://github.com/ayflying/p2p.git
synced 2026-03-04 17:29:22 +00:00
修复依赖
This commit is contained in:
@@ -53,7 +53,6 @@ var (
|
||||
"g,gateway": true,
|
||||
"a,action": true,
|
||||
"t,target": true,
|
||||
"m,message": true,
|
||||
})
|
||||
|
||||
// 获取运行模式参数
|
||||
@@ -78,12 +77,17 @@ var (
|
||||
wsStr := "ws://192.168.50.173:51888/ws"
|
||||
err = service.P2P().Start(ctx, wsStr)
|
||||
case "dht":
|
||||
h, _ := service.P2P().CreateLibp2pHost(ctx, 0)
|
||||
service.P2P().DHTStart(ctx, h)
|
||||
|
||||
default:
|
||||
// 显示帮助信息
|
||||
g.Log().Info(ctx, p2pHelpDescription)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package hello
|
||||
@@ -1,16 +0,0 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package hello
|
||||
|
||||
import (
|
||||
"github.com/ayflying/p2p/api/hello"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() hello.IHelloV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package hello
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
"github.com/ayflying/p2p/api/hello/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error) {
|
||||
g.RequestFromCtx(ctx).Response.Writeln("Hello World!")
|
||||
return
|
||||
}
|
||||
@@ -34,7 +34,7 @@ type Client struct {
|
||||
|
||||
func (s *sP2P) Start(ctx context.Context, wsStr string) (err error) {
|
||||
|
||||
hostObj, err := s.createLibp2pHost(ctx, 0)
|
||||
hostObj, err := s.CreateLibp2pHost(ctx, 0)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func (s *sP2P) Start(ctx context.Context, wsStr string) (err error) {
|
||||
}
|
||||
|
||||
// 创建libp2p主机
|
||||
func (s *sP2P) createLibp2pHost(ctx context.Context, port int) (host.Host, error) {
|
||||
func (s *sP2P) CreateLibp2pHost(ctx context.Context, port int) (host.Host, error) {
|
||||
if port == 0 {
|
||||
//port = grand.N(50000, 55000)
|
||||
port = 53533
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// 初始化无服务器DHT(作为节点加入DHT网络)
|
||||
func (s *sP2P) InitDHT(ctx context.Context, h host.Host) (*dht.IpfsDHT, error) {
|
||||
func (s *sP2P) DHTStart(ctx context.Context, h host.Host) (*dht.IpfsDHT, error) {
|
||||
// 创建DHT实例,设置为“客户端+服务端模式”(既可以查找数据,也可以存储数据)
|
||||
kdht, err := dht.New(ctx, h, dht.Mode(dht.ModeServer))
|
||||
if err != nil {
|
||||
|
||||
@@ -9,15 +9,21 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
dht "github.com/libp2p/go-libp2p-kad-dht"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
)
|
||||
|
||||
type (
|
||||
IP2P interface {
|
||||
Start(ctx context.Context, wsStr string) (err error)
|
||||
// 创建libp2p主机
|
||||
CreateLibp2pHost(ctx context.Context, port int) (host.Host, error)
|
||||
// 发现并连接目标节点
|
||||
DiscoverAndConnect(targetID string) error
|
||||
// 发送数据到目标节点
|
||||
SendData(targetID string, data []byte) error
|
||||
// 初始化无服务器DHT(作为节点加入DHT网络)
|
||||
DHTStart(ctx context.Context, h host.Host) (*dht.IpfsDHT, error)
|
||||
GatewayStart(ctx context.Context, group *ghttp.RouterGroup) (err error)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user