mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-29 22:39:26 -07:00
Merge pull request #368 from mrd0ll4r/udp-connect-af
udp: set address family for connect metrics
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -273,6 +274,16 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (actionName string
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
af = new(bittorrent.AddressFamily)
|
||||||
|
if r.IP.To4() != nil {
|
||||||
|
*af = bittorrent.IPv4
|
||||||
|
} else if len(r.IP) == net.IPv6len { // implies r.IP.To4() == nil
|
||||||
|
*af = bittorrent.IPv6
|
||||||
|
} else {
|
||||||
|
// Should never happen - we got the IP straight from the UDP packet.
|
||||||
|
panic(fmt.Sprintf("udp: invalid IP: neither v4 nor v6, IP: %#v", r.IP))
|
||||||
|
}
|
||||||
|
|
||||||
WriteConnectionID(w, txID, NewConnectionID(r.IP, timecache.Now(), t.PrivateKey))
|
WriteConnectionID(w, txID, NewConnectionID(r.IP, timecache.Now(), t.PrivateKey))
|
||||||
|
|
||||||
case announceActionID, announceV6ActionID:
|
case announceActionID, announceV6ActionID:
|
||||||
@@ -314,9 +325,8 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (actionName string
|
|||||||
} else if len(r.IP) == net.IPv6len { // implies r.IP.To4() == nil
|
} else if len(r.IP) == net.IPv6len { // implies r.IP.To4() == nil
|
||||||
req.AddressFamily = bittorrent.IPv6
|
req.AddressFamily = bittorrent.IPv6
|
||||||
} else {
|
} else {
|
||||||
log.Error("udp: invalid IP: neither v4 nor v6", log.Fields{"IP": r.IP})
|
// Should never happen - we got the IP straight from the UDP packet.
|
||||||
WriteError(w, txID, bittorrent.ErrInvalidIP)
|
panic(fmt.Sprintf("udp: invalid IP: neither v4 nor v6, IP: %#v", r.IP))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
af = new(bittorrent.AddressFamily)
|
af = new(bittorrent.AddressFamily)
|
||||||
*af = req.AddressFamily
|
*af = req.AddressFamily
|
||||||
|
|||||||
Reference in New Issue
Block a user