增加dht的去中心化储存

This commit is contained in:
2025-10-21 15:29:43 +08:00
parent 248f9a28e7
commit ab2f099826
14 changed files with 517 additions and 87 deletions

View File

@@ -18,7 +18,6 @@ import (
"github.com/google/uuid"
"github.com/gorilla/websocket"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
@@ -123,7 +122,8 @@ func (s *sP2P) CreateLibp2pHost(ctx context.Context, port int) (host.Host, error
}
// 1. 生成密钥对并初始化节点(确保身份有效)
s.privKey, _, _ = crypto.GenerateKeyPair(crypto.Ed25519, 0) // 推荐使用Ed25519
//s.privKey, _, _ = crypto.GenerateKeyPair(crypto.Ed25519, 0) // 推荐使用Ed25519
s.privKey, _ = s.generateFixedKey()
// 创建主机
h, err := libp2p.New(