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)
|
saveConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize P2P
|
// Generate Host ID
|
||||||
var nodeErr error
|
hostID, nodeErr := generateHostID()
|
||||||
hostID, nodeErr = initP2P()
|
|
||||||
if nodeErr != nil {
|
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 {
|
if len(config.Peers) > 0 {
|
||||||
time.Sleep(2 * time.Second) // Give some time for connections to establish
|
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"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
libp2p "github.com/libp2p/go-libp2p"
|
|
||||||
crypto "github.com/libp2p/go-libp2p-core/crypto"
|
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -21,7 +17,7 @@ var (
|
||||||
peers []string
|
peers []string
|
||||||
authMutex sync.Mutex
|
authMutex sync.Mutex
|
||||||
authenticated = make(map[string]bool)
|
authenticated = make(map[string]bool)
|
||||||
hostID peer.ID
|
hostID string
|
||||||
)
|
)
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
|
@ -43,18 +39,13 @@ func loadNodeConfig() {
|
||||||
peers = config.Peers
|
peers = config.Peers
|
||||||
}
|
}
|
||||||
|
|
||||||
func initP2P() (peer.ID, error) {
|
func generateHostID() (string, error) {
|
||||||
priv, _, err := crypto.GenerateKeyPairWithReader(crypto.Ed25519, 2048, rand.Reader)
|
bytes := make([]byte, 16)
|
||||||
|
_, err := rand.Read(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to generate key pair: %v", err)
|
return "", fmt.Errorf("failed to generate host ID: %v", err)
|
||||||
}
|
}
|
||||||
|
return fmt.Sprintf("%x", bytes), nil
|
||||||
h, err := libp2p.New(libp2p.Identity(priv))
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to create libp2p host: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return h.ID(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendMessage(serverAddr string, msg Message) error {
|
func sendMessage(serverAddr string, msg Message) error {
|
||||||
|
@ -118,7 +109,7 @@ func startNodeClient() {
|
||||||
for {
|
for {
|
||||||
for _, peerAddr := range peers {
|
for _, peerAddr := range peers {
|
||||||
msg := Message{
|
msg := Message{
|
||||||
ID: hostID.Pretty(),
|
ID: hostID,
|
||||||
Type: "test",
|
Type: "test",
|
||||||
Content: "This is a test message from the client node",
|
Content: "This is a test message from the client node",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue