2

I'm trying to implement a rate-limiter based on IP address, in a websocket application, but I can't figure out how to get the IP address as a string. I've been scouring the docs and there's no mention of IP address.

I have a addr: Recipient<WSMessage> and a context.

So far I've tried ctx.address() - Can't convert to string msg.addr.tx.0 - Can't unbox bc its private.

dessalines
  • 6,352
  • 5
  • 42
  • 59

1 Answers1

2

Figured it out:

fn chat_route(req: &HttpRequest<WsChatSessionState>) -> Result<HttpResponse, Error> {
    ws::start(
        req,
        WSSession {
            id: 0,
            hb: Instant::now(),
            ip: req.connection_info().remote().to_string(),
        },
    )
}
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
dessalines
  • 6,352
  • 5
  • 42
  • 59