javatcpzeromqjeromq

Using JeroMQ over TCP, is there a way to get a sender's IP?


Our application is using JeroMQ 0.4.3 to send messages between a client application and an API. (using curve encryption with ZAuth).

We're getting client messages from a ROUTER socket in our broker (MDP pattern).

What's the best way to find the sender's IP when receiving a message in the broker?

In ZeroMQ, it seems it might be possible using ZMQ_SRCFD message option and getpeername() but I have not found a way to translate that to JeroMQ.


Solution

  • The more recent ZeroMQ API indeed defines ZMQ_SRCFD property a message may carry.

    Fact A)
    one is principally never sure, what ZeroMQ API version ( 2.x ~ 3.x ~ 4.2.2 ~ ? as of EoY-2017 ) does the remote system use, unless some indeed rigid and intrusion-robust version-enforcement policy is put in place and active.

    Fact B)
    recent ZeroMQ API defines for tcp:// transport-class this:

    ZMQ_SRCFD
    Returns the file descriptor of the socket the message was read from. This allows application to retrieve the remote endpoint via getpeername(2). Be aware that the respective socket might be closed already, reused even. Currently only implemented for TCP sockets.

    Fact C)
    Any language wrapper or binding, including one's preferred JeroMQ or other, has to cover the selected scope ( be it a full or a partial scope-coverage ) on its own.

    If one lacks a feature in some particular language port/binding version, the best next step is to assess a feasibility of extending the published source code, so as to also cover a wished feature by (re)-implementing the language port/binding so as to best meet the desired API feature as specified by the ZeroMQ published specification.

    Fact D)
    In cases, where C) gets unfeasible or incomplete as per principal uncertainty expressed under B) , one may still proceed to rather implement one's own, high level IP-address node-(re)-discovery strategy, based on any suitable grade of security-concerns, starting from even a { naive self-declaration | two-step IP-validation | ... | a trust-less IP-validation }-protocol, if one needs it.