Skip to content

Commit

Permalink
remove references to observers
Browse files Browse the repository at this point in the history
  • Loading branch information
marcovidonis committed Feb 17, 2025
1 parent 19bbecf commit a7e2e90
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 64 deletions.
12 changes: 0 additions & 12 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,7 @@ func NewClient(cfg *ClientConfig) (cl *Client, err error) {
}
}

var obs *webtorrent.TrackerObserver
if cl.config.Observers != nil {
obs = &cl.config.Observers.Trackers
}
cl.websocketTrackers = websocketTrackers{
obs: obs,
PeerId: cl.peerID,
Logger: cl.logger.WithNames("websocketTrackers"),
GetAnnounceRequest: func(
Expand Down Expand Up @@ -749,10 +744,6 @@ func doProtocolHandshakeOnDialResult(
nc := dr.Conn
addrIpPort, _ := tryIpPortFromNetAddr(addr)

var obs *PeerObserver
if t.cl.config.Observers != nil {
obs = &t.cl.config.Observers.Peers
}
c, err = cl.initiateProtocolHandshakes(
context.Background(), nc, t, obfuscatedHeader,
newConnectionOpts{
Expand All @@ -762,7 +753,6 @@ func doProtocolHandshakeOnDialResult(
localPublicAddr: cl.publicAddr(addrIpPort.IP),
network: dr.Dialer.DialerNetwork(),
connString: regularNetConnPeerConnConnString(nc),
obs: obs,
})
if err != nil {
nc.Close()
Expand Down Expand Up @@ -1666,7 +1656,6 @@ type newConnectionOpts struct {
localPublicAddr peerLocalPublicAddr
network string
connString string
obs *PeerObserver
}

func (cl *Client) newConnection(nc net.Conn, opts newConnectionOpts) (c *PeerConn) {
Expand All @@ -1687,7 +1676,6 @@ func (cl *Client) newConnection(nc net.Conn, opts newConnectionOpts) (c *PeerCon
},
connString: opts.connString,
conn: nc,
Observers: opts.obs,
}
c.peerRequestDataAllocLimiter.Max = cl.config.MaxAllocPeerRequestDataPerConn
c.initRequestState()
Expand Down
20 changes: 0 additions & 20 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"net/url"
"time"

"github.com/anacrolix/torrent/webtorrent"

"github.com/anacrolix/dht/v2"
"github.com/anacrolix/dht/v2/krpc"
"github.com/anacrolix/log"
Expand All @@ -22,23 +20,6 @@ import (
"github.com/anacrolix/torrent/version"
)

type Observers struct {
Trackers webtorrent.TrackerObserver
Peers PeerObserver
}

func NewClientObservers() *Observers {
return &Observers{
Trackers: webtorrent.TrackerObserver{
ConnStatus: make(chan webtorrent.TrackerStatus),
AnnounceStatus: make(chan webtorrent.AnnounceStatus),
},
Peers: PeerObserver{
PeerStatus: make(chan PeerStatus),
},
}
}

// Contains config elements that are exclusive to tracker handling. There may be other fields in
// ClientConfig that are also relevant.
type ClientTrackerConfig struct {
Expand All @@ -51,7 +32,6 @@ type ClientTrackerConfig struct {
// Takes a tracker's hostname and requests DNS A and AAAA records.
// Used in case DNS lookups require a special setup (i.e., dns-over-https)
LookupTrackerIp func(*url.URL) ([]net.IP, error)
Observers *Observers
}

type ClientDhtConfig struct {
Expand Down
5 changes: 0 additions & 5 deletions peerconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ type PeerStatus struct {
Err string // see https://github.com/golang/go/issues/5161
}

type PeerObserver struct {
PeerStatus chan PeerStatus
}

// Maintains the state of a BitTorrent-protocol based connection with a peer.
type PeerConn struct {
Peer
Expand Down Expand Up @@ -100,7 +96,6 @@ type PeerConn struct {
// we can verify all the pieces for a file when they're all arrived before submitting them to
// the torrent.
receivedHashPieces map[[32]byte][][32]byte
Observers *PeerObserver
}

func (cn *PeerConn) pexStatus() string {
Expand Down
6 changes: 0 additions & 6 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1874,11 +1874,6 @@ func (t *Torrent) onWebRtcConn(
}
localAddrIpPort := missinggo.IpPortFromNetAddr(netConn.LocalAddr())

var obs *PeerObserver
if t.cl.config.Observers != nil {
obs = &t.cl.config.Observers.Peers
}

pc, err := t.cl.initiateProtocolHandshakes(
context.Background(),
netConn,
Expand All @@ -1890,7 +1885,6 @@ func (t *Torrent) onWebRtcConn(
localPublicAddr: localAddrIpPort,
network: webrtcNetwork,
connString: fmt.Sprintf("webrtc offer_id %x: %v", dcc.OfferId, regularNetConnPeerConnConnString(netConn)),
obs: obs,
},
)
if err != nil {
Expand Down
18 changes: 0 additions & 18 deletions webtorrent/tracker-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@ import (
"github.com/anacrolix/torrent/types/infohash"
)

type TrackerStatus struct {
Url string `json:"url"`
Ok bool `json:"ok"`
Err error `json:"err"`
}

type AnnounceStatus struct {
TrackerStatus
Event string `json:"event"`
InfoHash string `json:"info_hash"`
}

type TrackerObserver struct {
ConnStatus chan TrackerStatus
AnnounceStatus chan AnnounceStatus
}

type TrackerClientStats struct {
Dials int64
ConvertedInboundConns int64
Expand All @@ -50,7 +33,6 @@ type TrackerClient struct {
OnConn onDataChannelOpen
Logger log.Logger
Dialer *websocket.Dialer
Observers *TrackerObserver

mu sync.Mutex
cond sync.Cond
Expand Down
3 changes: 0 additions & 3 deletions wstracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type websocketTrackers struct {
OnConn func(webtorrent.DataChannelConn, webtorrent.DataChannelContext)
mu sync.Mutex
clients map[string]*refCountedWebtorrentTrackerClient
obs *webtorrent.TrackerObserver
Proxy httpTracker.ProxyFunc
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
WebsocketTrackerHttpHeader func() netHttp.Header
Expand All @@ -66,8 +65,6 @@ func (me *websocketTrackers) Get(url string, infoHash [20]byte) (*webtorrent.Tra
}
value = &refCountedWebtorrentTrackerClient{
TrackerClient: webtorrent.TrackerClient{
// TODO pass in callbacks rather than observers
Observers: me.obs,
Dialer: dialer,
Url: url,
GetAnnounceRequest: me.GetAnnounceRequest,
Expand Down

0 comments on commit a7e2e90

Please sign in to comment.