func NewSyncer(ctx context.Context, conf Configuration, ticker layerTicker, mesh *mesh.Mesh, fetcher layerFetcher, patrol layerPatrol, logger log.Log) *Syncer {
	shutdownCtx, cancel := context.WithCancel(ctx)
	return &Syncer{
		logger:            logger,
		conf:              conf,
		ticker:            ticker,
		mesh:              mesh,
		validator:         mesh,
		fetcher:           fetcher,
		patrol:            patrol,
		syncState:         notSynced,
		syncTimer:         time.NewTicker(conf.SyncInterval),
		targetSyncedLayer: unsafe.Pointer(&types.LayerID{}),
		awaitSyncedCh:     make([]chan struct{}, 0),
		forceSyncCh:       make(chan struct{}, 1),
		shutdownCtx:       shutdownCtx,
		cancelFunc:        cancel,
	}
}
NewSyncer creates a new Syncer instance.
package syncer
import (
	"context"
	"errors"
	"fmt"
	"sync"
	"sync/atomic"
	"time"
	"unsafe"
	"golang.org/x/sync/errgroup"
	"github.com/spacemeshos/go-spacemesh/common/types"
	"github.com/spacemeshos/go-spacemesh/events"
	"github.com/spacemeshos/go-spacemesh/layerfetcher"
	"github.com/spacemeshos/go-spacemesh/log"
	"github.com/spacemeshos/go-spacemesh/mesh"
)
type layerTicker interface {
	GetCurrentLayer() types.LayerID
	LayerToTime(types.LayerID) time.Time
}
type layerFetcher interface {
	PollLayerContent(ctx context.Context, layerID types.LayerID) chan layerfetcher.LayerPromiseResult
	GetEpochATXs(ctx context.Context, id types.EpochID) error
}
type layerPatrol interface {
	IsHareInCharge(types.LayerID) bool
}
type layerValidator interface {
	ValidateLayer(context.Context, *types.Layer)
}
type Configuration struct {
	SyncInterval time.Duration
	AlwaysListen bool
}
const (
	outOfSyncThreshold  uint32 = 3  
	numGossipSyncLayers uint32 = 2  
	maxHareDelayLayers uint32 = 10
)
type syncState uint32
const (
	notSynced syncState = iota
	gossipSync
	synced
)
func (s syncState) String() string {
	switch s {
	case notSynced:
		return "notSynced"
	case gossipSync:
		return "gossipSync"
	case synced:
		return "synced"
	default:
		return "unknown"
	}
}
type Syncer struct {
	logger log.Log
	conf      Configuration
	ticker    layerTicker
	mesh      *mesh.Mesh
	validator layerValidator
	fetcher   layerFetcher
	patrol    layerPatrol
	syncOnce  sync.Once
	syncState syncState
	isBusy    uint32
	syncTimer *time.Ticker
	targetSyncedLayer unsafe.Pointer
	awaitSyncedCh []chan struct{}
	awaitSyncedMu sync.Mutex
	forceSyncCh chan struct{}
	shutdownCtx context.Context
	cancelFunc  context.CancelFunc
	eg          errgroup.Group
	run uint64
}