Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
  • Loading branch information
gfanton committed Oct 20, 2022
1 parent 09a3055 commit 5c2b2a7
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 89 deletions.
10 changes: 0 additions & 10 deletions go/internal/initutil/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,16 +678,6 @@ func (m *Manager) configIPFSRouting(h host.Host, r p2p_routing.Routing) error {
discovery.FullJitter,
time.Second, 10.0, 0, serverRng)

// tinderOpts := &tinder.Opts{
// Logger: logger,
// AdvertiseResetInterval: time.Hour,
// FindPeerResetInterval: time.Minute * 10,
// AdvertiseGracePeriod: time.Minute,
// BackoffStrategy: &tinder.BackoffOpts{
// StratFactory: backoffstrat,
// },
// }

m.Node.Protocol.tinder, err = tinder.NewService(h, logger, drivers...)
if err != nil {
return errcode.ErrIPFSSetupHost.Wrap(err)
Expand Down
12 changes: 0 additions & 12 deletions go/internal/ipfsutil/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,6 @@ func TestingCoreAPIUsingMockNet(ctx context.Context, t testing.TB, opts *Testing
drivers = append(drivers, driver)
}

// minBackoff, maxBackoff := time.Second, time.Minute
// rng := rand.New(rand.NewSource(rand.Int63()))
// tinderOpts := &tinder.Opts{
// Logger: opts.Logger,
// AdvertiseResetInterval: time.Minute,
// AdvertiseGracePeriod: time.Minute,
// BackoffStrategy: &tinder.BackoffOpts{
// StratFactory: discovery.NewFixedBackoff(time.Second),
// },
// BackoffStratFactory: discovery.NewExponentialBackoff(minBackoff, maxBackoff, discovery.FullJitter, time.Second, 5.0, 0, rng),
// }

// enable discovery monitor
stinder, err = tinder.NewService(h, opts.Logger, drivers...)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion go/internal/rendezvous/emitterio_sync_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type emitterClientManager struct {
inChan chan *registrationMessage
mu sync.Mutex
logger *zap.Logger
wg sync.WaitGroup
}

func (e *emitterClient) subscribeToServerUpdates(inChan chan *registrationMessage, psDetails *EmitterPubSubSubscriptionDetails) (err error) {
Expand Down
3 changes: 2 additions & 1 deletion go/internal/tinder/driver_localdiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func (ld *LocalDiscovery) FindPeers(ctx context.Context, cid string, opts ...dis

for _, rec := range cache.recs {
out <- *rec.peer
if size = size - 1; size == 0 {
size--
if size == 0 {
break
}
}
Expand Down
3 changes: 1 addition & 2 deletions go/internal/tinder/driver_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func (s *MockDriverServer) Subscribe(ctx context.Context, topic string, buffsize
for _, peer := range s.pc.GetPeers(updated...) {
out <- peer
}

}

// we're done here, close the channel and decrement
Expand Down Expand Up @@ -214,7 +213,7 @@ const (
optionSubscribeBufferSize discOption = "tinder_subsize"
)

func mockBufferSize(size int) discovery.Option {
func MockBufferSize(size int) discovery.Option {
return func(opts *discovery.Options) error {
if opts.Other == nil {
opts.Other = make(map[interface{}]interface{})
Expand Down
25 changes: 0 additions & 25 deletions go/internal/tinder/options.go

This file was deleted.

11 changes: 5 additions & 6 deletions go/internal/tinder/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"fmt"
"sync"
"sync/atomic"
"time"

"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
"go.uber.org/zap"

"berty.tech/berty/v2/go/internal/logutil"
)

type Service struct {
Expand All @@ -26,10 +27,6 @@ type Service struct {
process uint32
}

type RegisterOption struct {
gracePeriode time.Duration
}

func NewService(h host.Host, logger *zap.Logger, drivers ...IDriver) (*Service, error) {
nn, err := NewNetworkUpdate(logger, h)
if err != nil {
Expand All @@ -52,7 +49,9 @@ func (s *Service) FindPeers(ctx context.Context, topic string) <-chan peer.AddrI

ctx, cancel := context.WithCancel(ctx)
go func() {
s.LookupPeers(ctx, topic)
if err := s.LookupPeers(ctx, topic); err != nil {
s.logger.Error("lookup failed", logutil.PrivateString("topic", topic), zap.Error(err))
}
cancel()
}()

Expand Down
14 changes: 11 additions & 3 deletions go/internal/tinder/service_adaptater.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,20 @@ func (a *DiscoveryAdaptater) Advertise(_ context.Context, topic string, opts ...
a.muAdvertiser.Unlock()

// unregister from this topic if possible
a.service.UnRegister(ctx, topic)
if err := a.service.UnRegister(ctx, topic); err != nil {
a.logger.Debug("unregister failed",
logutil.PrivateString("topic", topic),
zap.Error(err),
)
}
})

// start advertising on this topic
a.service.Advertises(wctx, topic, AdvertisesFilterDrivers(LocalDiscoveryName))
a.logger.Debug("advertise started", logutil.PrivateString("topic", topic))
if err := a.service.Advertises(wctx, topic, AdvertisesFilterDrivers(LocalDiscoveryName)); err != nil {
a.logger.Error("advertise failed", logutil.PrivateString("topic", topic), zap.Error(err))
} else {
a.logger.Debug("advertise started", logutil.PrivateString("topic", topic))
}
}

a.muAdvertiser.Unlock()
Expand Down
31 changes: 6 additions & 25 deletions go/internal/tinder/service_advertises.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func (s *Service) Advertises(ctx context.Context, topic string, opts ...Advertis
}
// @TODO(gfanton): add filter
for _, driver := range s.drivers {
// if aopts.Filters != nil {
// // skip filter driver
// if _, filter := aopts.Filters[driver.Name()]; filter {
// continue
// }
// }
if aopts.Filters != nil {
// skip filter driver
if _, filter := aopts.Filters[driver.Name()]; filter {
continue
}
}

go func(driver IDriver) {
if err := s.advertise(ctx, driver, topic); err != nil {
Expand Down Expand Up @@ -120,22 +120,3 @@ func (s *Service) advertise(ctx context.Context, d IDriver, topic string) error
}
}
}

// func (s *Service) advertises(ctx context.Context, topic string, opts ...p2p_discovery.Option) {

// // var filters []string
// // if f, ok := optiotopic.Other[optionFilterDriver]; ok {
// // if filters, ok = f.([]string); !ok {
// // s.logger.Error("unable to parse filter driver option")
// // return
// // }
// // }

// for _, d := range s.drivers {
// // if shoudlFilterDriver(d.Name, filters) {
// // continue
// // }

// go s.advertise(ctx, d, topic, opts...)
// }
// }
1 change: 0 additions & 1 deletion go/internal/tinder/service_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func (s *Service) LookupPeers(ctx context.Context, topic string) error {

wg.Done()
}(d)

}

wg.Wait() // wait for process to finish
Expand Down
9 changes: 6 additions & 3 deletions go/pkg/bertyprotocol/tinder_swiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (s *Swiper) WatchTopic(ctx context.Context, topic, seed []byte) <-chan peer
return cpeers
}

func (s *Swiper) watchPeers(ctx context.Context, bstrat discovery.BackoffStrategy, out chan<- peer.AddrInfo, topic string) error {
func (s *Swiper) watchPeers(ctx context.Context, _ discovery.BackoffStrategy, out chan<- peer.AddrInfo, topic string) error {
sub := s.tinder.Subscribe(topic)
defer sub.Close()
// func () {
Expand All @@ -190,7 +190,6 @@ func (s *Swiper) watchPeers(ctx context.Context, bstrat discovery.BackoffStrateg
select {
case <-time.After(timeout):
case <-ctx.Done():

}
}
}()
Expand Down Expand Up @@ -224,7 +223,11 @@ func (s *Swiper) Announce(ctx context.Context, topic, seed []byte) {
s.logger.Debug("self announce topic for time", logutil.PrivateString("topic", point.RotationTopic()))

actx, cancel := context.WithDeadline(ctx, point.Deadline())
s.tinder.Advertises(actx, point.RotationTopic())
if err := s.tinder.Advertises(actx, point.RotationTopic()); err != nil && err != ctx.Err() {
cancel()
<-time.After(time.Second * 10) // retry after 10sc
continue
}

select {
case <-actx.Done():
Expand Down

0 comments on commit 5c2b2a7

Please sign in to comment.