refactor: use clientIP and pass in a wrapped net.IPAddr

This commit is contained in:
Derrick Hammer 2024-03-10 09:09:29 -04:00
parent 195abfdf20
commit bb1b43958a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 5 deletions

View File

@ -85,8 +85,6 @@ func (h *HTTPServiceDefault) p2pHandler(ctx jape.Context) {
return return
} }
ip := peer.GetIP()
// Check for reverse proxy headers // Check for reverse proxy headers
realIP := ctx.Request.Header.Get("X-Real-IP") realIP := ctx.Request.Header.Get("X-Real-IP")
forwardedFor := ctx.Request.Header.Get("X-Forwarded-For") forwardedFor := ctx.Request.Header.Get("X-Forwarded-For")
@ -117,7 +115,7 @@ func (h *HTTPServiceDefault) p2pHandler(ctx jape.Context) {
} }
} }
if blockConnection(ip) { if blockConnection(peer.GetIP()) {
err := peer.End() err := peer.End()
if err != nil { if err != nil {
h.Logger().Error("error ending peer", zap.Error(err)) h.Logger().Error("error ending peer", zap.Error(err))
@ -125,8 +123,8 @@ func (h *HTTPServiceDefault) p2pHandler(ctx jape.Context) {
return return
} }
if ip != nil { if clientIP != nil {
peer.SetIP(ip) peer.SetIP(&net.IPAddr{IP: clientIP})
} }
h.Services().P2P().ConnectionTracker().Add(1) h.Services().P2P().ConnectionTracker().Add(1)