remove "libcrypto" since it was not really used
This commit is contained in:
parent
9f655ba8c0
commit
b92d2c732b
2 changed files with 11 additions and 21 deletions
9
init.go
9
init.go
|
@ -57,13 +57,12 @@ func main() {
|
|||
saveConfig(config)
|
||||
}
|
||||
|
||||
// Initialize P2P
|
||||
var nodeErr error
|
||||
hostID, nodeErr = initP2P()
|
||||
// Generate Host ID
|
||||
hostID, nodeErr := generateHostID()
|
||||
if nodeErr != nil {
|
||||
log.Fatalf("Failed to initialize P2P: %v", nodeErr)
|
||||
log.Fatalf("Failed to generate host ID: %v", nodeErr)
|
||||
}
|
||||
config.PeerID = hostID.String()
|
||||
config.PeerID = hostID
|
||||
|
||||
if len(config.Peers) > 0 {
|
||||
time.Sleep(2 * time.Second) // Give some time for connections to establish
|
||||
|
|
23
node.go
23
node.go
|
@ -10,10 +10,6 @@ import (
|
|||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
libp2p "github.com/libp2p/go-libp2p"
|
||||
crypto "github.com/libp2p/go-libp2p-core/crypto"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -21,7 +17,7 @@ var (
|
|||
peers []string
|
||||
authMutex sync.Mutex
|
||||
authenticated = make(map[string]bool)
|
||||
hostID peer.ID
|
||||
hostID string
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
|
@ -43,18 +39,13 @@ func loadNodeConfig() {
|
|||
peers = config.Peers
|
||||
}
|
||||
|
||||
func initP2P() (peer.ID, error) {
|
||||
priv, _, err := crypto.GenerateKeyPairWithReader(crypto.Ed25519, 2048, rand.Reader)
|
||||
func generateHostID() (string, error) {
|
||||
bytes := make([]byte, 16)
|
||||
_, err := rand.Read(bytes)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to generate key pair: %v", err)
|
||||
return "", fmt.Errorf("failed to generate host ID: %v", err)
|
||||
}
|
||||
|
||||
h, err := libp2p.New(libp2p.Identity(priv))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create libp2p host: %v", err)
|
||||
}
|
||||
|
||||
return h.ID(), nil
|
||||
return fmt.Sprintf("%x", bytes), nil
|
||||
}
|
||||
|
||||
func sendMessage(serverAddr string, msg Message) error {
|
||||
|
@ -118,7 +109,7 @@ func startNodeClient() {
|
|||
for {
|
||||
for _, peerAddr := range peers {
|
||||
msg := Message{
|
||||
ID: hostID.Pretty(),
|
||||
ID: hostID,
|
||||
Type: "test",
|
||||
Content: "This is a test message from the client node",
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue