33 lines
754 B
Go
33 lines
754 B
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"dejo_node/internal/storage"
|
|
|
|
host "github.com/libp2p/go-libp2p/core/host"
|
|
)
|
|
|
|
const SyncProtocolID = "/dejo/sync/1.0.0"
|
|
|
|
// SyncManager coordena o processo de sincronização de blocos com outros peers.
|
|
type SyncManager struct {
|
|
Ctx context.Context
|
|
Host host.Host
|
|
BlockStore *storage.BlockStore
|
|
}
|
|
|
|
// NewSyncManager cria um novo gerenciador de sincronização.
|
|
func NewSyncManager(ctx context.Context, h host.Host, bs *storage.BlockStore) *SyncManager {
|
|
manager := &SyncManager{
|
|
Ctx: ctx,
|
|
Host: h,
|
|
BlockStore: bs,
|
|
}
|
|
|
|
h.SetStreamHandler(SyncProtocolID, manager.handleStream)
|
|
fmt.Println("🔄 Handler de sync registrado para protocolo:", SyncProtocolID)
|
|
|
|
return manager
|
|
} |