mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-27 01:48:09 -07:00
refactor timecache
* change clock to `atomic.Int64` * add `once` fields for starter and stopper * update dependencies note: go version updated to 1.19
This commit is contained in:
@@ -160,10 +160,6 @@ func (ps *peerStore) ScheduleStatisticsCollection(reportInterval time.Duration)
|
||||
}()
|
||||
}
|
||||
|
||||
func (ps *peerStore) getClock() int64 {
|
||||
return timecache.NowUnixNano()
|
||||
}
|
||||
|
||||
func (ps *peerStore) shardIndex(infoHash bittorrent.InfoHash, v6 bool) uint32 {
|
||||
// There are twice the amount of shards specified by the user, the first
|
||||
// half is dedicated to IPv4 swarms and the second half is dedicated to
|
||||
@@ -203,7 +199,7 @@ func (ps *peerStore) PutSeeder(_ context.Context, ih bittorrent.InfoHash, p bitt
|
||||
}
|
||||
|
||||
// Update the peer in the swarm.
|
||||
shard.swarms[ih].seeders[p] = ps.getClock()
|
||||
shard.swarms[ih].seeders[p] = timecache.NowUnixNano()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -269,7 +265,7 @@ func (ps *peerStore) PutLeecher(_ context.Context, ih bittorrent.InfoHash, p bit
|
||||
}
|
||||
|
||||
// Update the peer in the swarm.
|
||||
shard.swarms[ih].leechers[p] = ps.getClock()
|
||||
shard.swarms[ih].leechers[p] = timecache.NowUnixNano()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -341,7 +337,7 @@ func (ps *peerStore) GraduateLeecher(_ context.Context, ih bittorrent.InfoHash,
|
||||
}
|
||||
|
||||
// Update the peer in the swarm.
|
||||
shard.swarms[ih].seeders[p] = ps.getClock()
|
||||
shard.swarms[ih].seeders[p] = timecache.NowUnixNano()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ func (s *store) putPeer(ctx context.Context, ih bittorrent.InfoHash, peer bittor
|
||||
Object("peer", peer).
|
||||
Bool("seeder", seeder).
|
||||
Msg("put peer")
|
||||
args := pgx.NamedArgs{
|
||||
_, err = s.Exec(ctx, s.Peer.AddQuery, pgx.NamedArgs{
|
||||
pInfoHash: []byte(ih),
|
||||
pPeerID: peer.ID[:],
|
||||
pAddress: net.IP(peer.Addr().AsSlice()),
|
||||
@@ -362,8 +362,7 @@ func (s *store) putPeer(ctx context.Context, ih bittorrent.InfoHash, peer bittor
|
||||
pSeeder: seeder,
|
||||
pV6: peer.Addr().Is6(),
|
||||
pCreated: timecache.Now(),
|
||||
}
|
||||
_, err = s.Exec(ctx, s.Peer.AddQuery, args)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user