Example #1
0
func New(options ...func(*Tracker)) (*Tracker, error) {
	tracker := &Tracker{
		blocks: parmap.New(),
		txs:    parmap.New(),
	}

	for _, option := range options {
		option(tracker)
	}

	return tracker, nil
}
Example #2
0
// New returns a new manager initialized with the given options.
func New(options ...func(mgr *Manager)) (*Manager, error) {
	mgr := &Manager{
		wg:  &sync.WaitGroup{},
		sig: make(chan struct{}),

		incomingQ:  make(chan adaptor.Peer, 1),
		outgoingQ:  make(chan adaptor.Peer, 1),
		connectedQ: make(chan adaptor.Peer, 1),
		readyQ:     make(chan adaptor.Peer, 1),
		stoppedQ:   make(chan adaptor.Peer, 1),

		peerIndex:   parmap.New(),
		listenIndex: make(map[string]*net.TCPListener),

		network:        wire.TestNet3,
		version:        wire.RejectVersion,
		connRate:       time.Second / 10,
		connLimit:      100,
		tickerInterval: time.Second * 10,
	}

	nonce, err := wire.RandomUint64()
	if err != nil {
		return nil, err
	}

	mgr.nonce = nonce

	for _, option := range options {
		option(mgr)
	}

	return mgr, nil
}