Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
rename for better [shipit]
Browse files Browse the repository at this point in the history
Signed-off-by: Merlin Ran <merlinran@gmail.com>
  • Loading branch information
merlinran committed Oct 7, 2021
1 parent 7d11e23 commit 64956fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
13 changes: 4 additions & 9 deletions service/comm/libp2p_pubsub.go → service/libp2p_pubsub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package comm
package service

import (
"context"
Expand All @@ -10,16 +10,11 @@ import (
rpc "github.com/textileio/go-libp2p-pubsub-rpc"
"github.com/textileio/go-libp2p-pubsub-rpc/finalizer"
"github.com/textileio/go-libp2p-pubsub-rpc/peer"
golog "github.com/textileio/go-log/v2"
"google.golang.org/protobuf/proto"
)

var (
log = golog.Logger("bidbot/comm")
)

// Comm represents the communication channel with auctioneer.
type Comm interface {
// CommChannel represents the communication channel with auctioneer.
type CommChannel interface {
Subscribe(bootstrap bool, eh MessageHandler) error
Close() error
ID() core.ID
Expand All @@ -44,7 +39,7 @@ type Libp2pPubsub struct {
eventsTopic *rpc.Topic
}

// NewLibp2pPubsub creates a Comm backed by libp2p pubsub.
// NewLibp2pPubsub creates a communication channel backed by libp2p pubsub.
func NewLibp2pPubsub(ctx context.Context, conf peer.Config) (*Libp2pPubsub, error) {
fin := finalizer.NewFinalizer()
p, err := peer.New(conf)
Expand Down
17 changes: 8 additions & 9 deletions service/progress_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (

pb "github.com/textileio/bidbot/gen/v1"
"github.com/textileio/bidbot/lib/auction"
"github.com/textileio/bidbot/service/comm"
"google.golang.org/protobuf/types/known/timestamppb"
)

type progressReporter struct {
comm comm.Comm
ctx context.Context
commChannel CommChannel
ctx context.Context
}

func (pr progressReporter) StartFetching(bidID auction.BidID, attempts uint32) {
Expand All @@ -23,7 +22,7 @@ func (pr progressReporter) StartFetching(bidID auction.BidID, attempts uint32) {
Attempts: attempts,
}},
}
pr.comm.PublishBidbotEvent(pr.ctx, event)
pr.commChannel.PublishBidbotEvent(pr.ctx, event)
}
func (pr progressReporter) ErrorFetching(bidID auction.BidID, attempts uint32, err error) {
if err == nil {
Expand All @@ -37,7 +36,7 @@ func (pr progressReporter) ErrorFetching(bidID auction.BidID, attempts uint32, e
Error: err.Error(),
}},
}
pr.comm.PublishBidbotEvent(pr.ctx, event)
pr.commChannel.PublishBidbotEvent(pr.ctx, event)
}
func (pr progressReporter) StartImporting(bidID auction.BidID, attempts uint32) {
event := &pb.BidbotEvent{
Expand All @@ -47,7 +46,7 @@ func (pr progressReporter) StartImporting(bidID auction.BidID, attempts uint32)
Attempts: attempts,
}},
}
pr.comm.PublishBidbotEvent(pr.ctx, event)
pr.commChannel.PublishBidbotEvent(pr.ctx, event)
}

func (pr progressReporter) EndImporting(bidID auction.BidID, attempts uint32, err error) {
Expand All @@ -63,7 +62,7 @@ func (pr progressReporter) EndImporting(bidID auction.BidID, attempts uint32, er
event.Type.(*pb.BidbotEvent_EndImporting_).EndImporting.Error = err.Error()
}

pr.comm.PublishBidbotEvent(pr.ctx, event)
pr.commChannel.PublishBidbotEvent(pr.ctx, event)
}

func (pr progressReporter) Finalized(bidID auction.BidID) {
Expand All @@ -73,7 +72,7 @@ func (pr progressReporter) Finalized(bidID auction.BidID) {
BidId: string(bidID),
}},
}
pr.comm.PublishBidbotEvent(pr.ctx, event)
pr.commChannel.PublishBidbotEvent(pr.ctx, event)
}

func (pr progressReporter) Errored(bidID auction.BidID, errorCause string) {
Expand All @@ -84,5 +83,5 @@ func (pr progressReporter) Errored(bidID auction.BidID, errorCause string) {
ErrorCause: errorCause,
}},
}
pr.comm.PublishBidbotEvent(pr.ctx, event)
pr.commChannel.PublishBidbotEvent(pr.ctx, event)
}
31 changes: 15 additions & 16 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/textileio/bidbot/lib/datauri"
"github.com/textileio/bidbot/lib/dshelper/txndswrap"
"github.com/textileio/bidbot/lib/filclient"
"github.com/textileio/bidbot/service/comm"
"github.com/textileio/bidbot/service/limiter"
"github.com/textileio/bidbot/service/lotusclient"
"github.com/textileio/bidbot/service/pricing"
Expand Down Expand Up @@ -148,11 +147,11 @@ func (f *MinMaxFilter) Validate() error {

// Service is a miner service that subscribes to auctions.
type Service struct {
comm comm.Comm
decryptKey tcrypto.DecryptionKey
fc filclient.FilClient
lc lotusclient.LotusClient
store *bidstore.Store
commChannel CommChannel
decryptKey tcrypto.DecryptionKey
fc filclient.FilClient
lc lotusclient.LotusClient
store *bidstore.Store

bidParams BidParams
auctionFilters AuctionFilters
Expand Down Expand Up @@ -182,11 +181,11 @@ func New(
ctx, cancel := context.WithCancel(context.Background())
fin.Add(finalizer.NewContextCloser(cancel))

comm, err := comm.NewLibp2pPubsub(ctx, conf.Peer)
commChannel, err := NewLibp2pPubsub(ctx, conf.Peer)
if err != nil {
return nil, fin.Cleanupf("creating peer: %v", err)
}
fin.Add(comm)
fin.Add(commChannel)

// Create bid store
s, err := bidstore.NewStore(
Expand All @@ -195,7 +194,7 @@ func New(
conf.BidParams.DealDataDirectory,
conf.BidParams.DealDataFetchAttempts,
conf.BidParams.DealDataFetchTimeout,
progressReporter{comm, ctx},
progressReporter{commChannel, ctx},
conf.BidParams.DiscardOrphanDealsAfter,
conf.BytesLimiter,
conf.ConcurrentImports,
Expand All @@ -208,7 +207,7 @@ func New(
// Verify StorageProvider ID
ok, err := fc.VerifyBidder(
conf.BidParams.WalletAddrSig,
comm.ID(),
commChannel.ID(),
conf.BidParams.StorageProviderID)
if err != nil {
return nil, fin.Cleanupf("verifying StorageProvider ID: %v", err)
Expand All @@ -227,7 +226,7 @@ func New(
}

srv := &Service{
comm: comm,
commChannel: commChannel,
decryptKey: decryptKey,
fc: fc,
lc: lc,
Expand Down Expand Up @@ -259,7 +258,7 @@ func (s *Service) Close() error {
// Subscribe to the deal auction feed.
// If bootstrap is true, the peer will dial the configured bootstrap addresses before joining the deal auction feed.
func (s *Service) Subscribe(bootstrap bool) error {
err := s.comm.Subscribe(bootstrap, s)
err := s.commChannel.Subscribe(bootstrap, s)
if err == nil {
s.reportStartup()
}
Expand All @@ -268,7 +267,7 @@ func (s *Service) Subscribe(bootstrap bool) error {

// PeerInfo returns the public information of the market peer.
func (s *Service) PeerInfo() (*peer.Info, error) {
return s.comm.Info()
return s.commChannel.Info()
}

// ListBids lists bids by applying a store.Query.
Expand Down Expand Up @@ -365,7 +364,7 @@ func (s *Service) makeBid(a *pb.Auction, from core.ID) error {
ctx2, cancel2 := context.WithTimeout(s.ctx, bidsAckTimeout)
defer cancel2()

id, err := s.comm.PublishBid(ctx2, auction.BidsTopic(auction.ID(a.Id)), bid)
id, err := s.commChannel.PublishBid(ctx2, auction.BidsTopic(auction.ID(a.Id)), bid)
if err != nil {
return fmt.Errorf("sending bid: %v", err)
}
Expand Down Expand Up @@ -506,7 +505,7 @@ func (s *Service) reportStartup() {
CidGravityStrict: s.pricingRulesStrict,
}},
}
s.comm.PublishBidbotEvent(s.ctx, event)
s.commChannel.PublishBidbotEvent(s.ctx, event)
}

func (s *Service) reportUnhealthy(err error) {
Expand All @@ -517,5 +516,5 @@ func (s *Service) reportUnhealthy(err error) {
Error: err.Error(),
}},
}
s.comm.PublishBidbotEvent(s.ctx, event)
s.commChannel.PublishBidbotEvent(s.ctx, event)
}

0 comments on commit 64956fc

Please sign in to comment.