MCPcopy
hub / github.com/webtorrent/bittorrent-tracker / onUdpRequest

Method onUdpRequest

server.js:407–443  ·  view source on GitHub ↗
(msg, rinfo)

Source from the content-addressed store, hash-verified

405 }
406
407 onUdpRequest (msg, rinfo) {
408 let params
409 try {
410 params = parseUdpRequest(msg, rinfo)
411 } catch (err) {
412 this.emit('warning', err)
413 // Do not reply for parsing errors
414 return
415 }
416
417 this._onRequest(params, (err, response) => {
418 if (err) {
419 this.emit('warning', err)
420 response = {
421 action: common.ACTIONS.ERROR,
422 'failure reason': err.message
423 }
424 }
425 if (this.destroyed) return
426
427 response.transactionId = params.transactionId
428 response.connectionId = params.connectionId
429
430 const buf = makeUdpPacket(response)
431
432 try {
433 const udp = (rinfo.family === 'IPv4') ? this.udp4 : this.udp6
434 udp.send(buf, 0, buf.length, rinfo.port, rinfo.address)
435 } catch (err) {
436 this.emit('warning', err)
437 }
438
439 if (params.action === common.ACTIONS.ANNOUNCE) {
440 this.emit(common.EVENT_NAMES[params.event], params.addr, params)
441 }
442 })
443 }
444
445 onWebSocketConnection (socket, opts = {}) {
446 opts.trustProxy = opts.trustProxy || this._trustProxy

Callers 1

constructorMethod · 0.95

Calls 3

_onRequestMethod · 0.95
makeUdpPacketFunction · 0.85
sendMethod · 0.80

Tested by

no test coverage detected