use peer.ID instead of string

This commit is contained in:
Richard Ramos 2021-04-15 13:55:40 -04:00
parent 01328daae6
commit 7ba8c51bca
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F

View File

@ -381,7 +381,7 @@ func GenerateRequestId() []byte {
rng := brHmacDrbgPool.Get().(*hmacdrbg.HmacDrbg) rng := brHmacDrbgPool.Get().(*hmacdrbg.HmacDrbg)
defer brHmacDrbgPool.Put(rng) defer brHmacDrbgPool.Put(rng)
randData := make([]byte, 10) randData := make([]byte, 32)
if !rng.Generate(randData) { if !rng.Generate(randData) {
//Reseed is required every 10,000 calls //Reseed is required every 10,000 calls
seed := make([]byte, 48) seed := make([]byte, 48)
@ -403,7 +403,7 @@ func GenerateRequestId() []byte {
} }
type HistoryRequestParameters struct { type HistoryRequestParameters struct {
selectedPeer *peer.ID selectedPeer peer.ID
requestId []byte requestId []byte
timeout *time.Duration timeout *time.Duration
ctx context.Context ctx context.Context
@ -418,16 +418,16 @@ type HistoryRequestParameters struct {
type HistoryRequestOption func(*HistoryRequestParameters) type HistoryRequestOption func(*HistoryRequestParameters)
func WithPeer(p string) HistoryRequestOption { func WithPeer(p peer.ID) HistoryRequestOption {
return func(params *HistoryRequestParameters) { return func(params *HistoryRequestParameters) {
pid := peer.ID(p) params.selectedPeer = p
params.selectedPeer = &pid
} }
} }
func WithAutomaticPeerSelection() HistoryRequestOption { func WithAutomaticPeerSelection() HistoryRequestOption {
return func(params *HistoryRequestParameters) { return func(params *HistoryRequestParameters) {
params.selectedPeer = params.s.selectPeer() p := params.s.selectPeer()
params.selectedPeer = *p
} }
} }
@ -479,7 +479,7 @@ func (store *WakuStore) Query(q *protocol.HistoryQuery, opts ...HistoryRequestOp
opt(params) opt(params)
} }
if params.selectedPeer == nil { if params.selectedPeer == "" {
return nil, ErrNoPeersAvailable return nil, ErrNoPeersAvailable
} }
@ -511,7 +511,7 @@ func (store *WakuStore) Query(q *protocol.HistoryQuery, opts ...HistoryRequestOp
q.PagingInfo.PageSize = params.pageSize q.PagingInfo.PageSize = params.pageSize
connOpt, err := store.h.NewStream(params.ctx, *params.selectedPeer, WakuStoreProtocolId) connOpt, err := store.h.NewStream(params.ctx, params.selectedPeer, WakuStoreProtocolId)
if err != nil { if err != nil {
log.Info("failed to connect to remote peer", err) log.Info("failed to connect to remote peer", err)
return nil, err return nil, err