Add announcePeer feature.

TODO:
	fix sync write
	congestion control
	Request timeout
This commit is contained in:
2026-01-22 13:55:29 +09:00
parent 60ec9c19ea
commit aa0c61139f
6 changed files with 102 additions and 68 deletions

View File

@@ -63,10 +63,13 @@ func (dp *dialPool) stop() {
func (dp *dialPool) connectLoop(ctx context.Context) {
dhtCtx, cancel := context.WithTimeout(ctx, dhtTimeout)
// TODO: handle tokens
addrs, _, err := dp.dht.GetPeers(dhtCtx, dp.infoHash)
addrs, tokens, err := dp.dht.GetPeers(dhtCtx, dp.infoHash)
cancel()
if len(tokens) > 0 {
dp.dht.AnnouncePeer(ctx, dp.infoHash, tokens)
}
if err != nil {
select {
case dp.results <- dialResult{done: true, err: err}:

View File

@@ -26,7 +26,7 @@ const (
const (
maxPeers = 8
maxPending = 5
maxPending = 50
dialTimeout = 30 * time.Second
retryInterval = 30 * time.Second
dhtTimeout = 5 * time.Minute