Encapsulate a network peer. More...
#include <DwmCredencePeer.hh>
Public Member Functions | |
| Peer () | |
| Default constructor. | |
| void | SetKeyExchangeTimeout (std::chrono::milliseconds ms) |
| Sets the time we'll wait for the peer to send its public key. | |
| bool | Accept (boost::asio::ip::tcp::socket &&s) |
Used by a server to accept a new connection on the given TCP socket s. | |
| bool | Accept (boost::asio::local::stream_protocol::socket &&s) |
Used by a server to accept a new connection on the given UNIX domain socket s. | |
| bool | Connect (const std::string &host, uint16_t port, std::chrono::milliseconds timeOut=std::chrono::milliseconds(5000)) |
Used by a client to connect to host at the given port, waiting timeOut for success. | |
| bool | Connect (const std::string &path, std::chrono::milliseconds timeOut=std::chrono::milliseconds(5000)) |
Used by a client to connect to a UNIX domain socket at the given path, waiting timeOut for success. | |
| void | SetIdExchangeTimeout (std::chrono::milliseconds ms) |
| Sets the time we'll wait for the peer to send its ID during authentication. | |
| bool | Authenticate (const KeyStash &keyStash, const KnownKeys &knownKeys) |
Using the given keyStash and knownKeys, authenticate our identity to the peer and verify the peer's identity. | |
| const std::string & | Id () const |
| If Authenticate() was used, returns the peer's identifier. | |
| template<typename T > | |
| bool | Send (const T &msg) |
Sends the given msg to the peer. | |
| template<typename T > | |
| bool | Receive (T &msg) |
Receives the given msg from the peer. | |
| bool | ReceiveWouldBlock (size_t numBytes) |
Returns true if a Receive() of numBytes or greater would block. | |
| void | Disconnect () |
| Disconnects the peer. | |
| std::string | EndPointString () const |
| Returns a string representation of the peer endpoint, in 'addr:port' form. | |
Encapsulate a network peer.
Note that once a connection is set up with Accept() or Connect(), all traffic will be encrypted with XChacha20Poly1305. Identity authentication (via the Authenticate() member function) after Accept() or Connect() is optional but highly recommended, as I don't have any production code that doesn't use it.
| bool Dwm::Credence::Peer::Accept | ( | boost::asio::ip::tcp::socket && | s | ) |
Used by a server to accept a new connection on the given TCP socket s.
Returns true on success, false on failure. Note that s is expected to be a socket that was already accepted (via Boost::asio::ip::tcp::acceptor::accept()).
| bool Dwm::Credence::Peer::Accept | ( | boost::asio::local::stream_protocol::socket && | s | ) |
Used by a server to accept a new connection on the given UNIX domain socket s.
Returns true on success, false on failure. Note that s is expected to be a socket that was already accepted (via Boost::asio::local::stream_protocol::acceptor::accept()).
Using the given keyStash and knownKeys, authenticate our identity to the peer and verify the peer's identity.
This is done using randomly generated challenges which must be signed with an Ed25519 key. Since this should be called immediately after Accept() or Connect(), the entire transaction is encrypted with XChaCha20Poly1305. Returns true on success, false on failure.
| bool Dwm::Credence::Peer::Connect | ( | const std::string & | host, |
| uint16_t | port, | ||
| std::chrono::milliseconds | timeOut = std::chrono::milliseconds(5000) ) |
Used by a client to connect to host at the given port, waiting timeOut for success.
Returns true on success, false on failure.
| bool Dwm::Credence::Peer::Connect | ( | const std::string & | path, |
| std::chrono::milliseconds | timeOut = std::chrono::milliseconds(5000) ) |
Used by a client to connect to a UNIX domain socket at the given path, waiting timeOut for success.
Returns true on success, false on failure.
|
inline |
Receives the given msg from the peer.
Returns true on success, false on failure. Note that T must be supported directly by a Dwm::StreamIO::Read() function (See DwmStreamIO.hh in libDwm) or meet the requirements of the Dwm::HasStreamRead concept (see DwmStreamIOCapable.hh in libDwm).

|
inline |
Sends the given msg to the peer.
Returns true on success, false on failure. Note that T must be supported directly by a Dwm::StreamIO::Write() function (see DwmStreamIO.hh in libDwm) or meet the requirements of the Dwm::HasStreamWrite concept (see DwmStreamIOCapable.hh in libDwm).

| void Dwm::Credence::Peer::SetIdExchangeTimeout | ( | std::chrono::milliseconds | ms | ) |
Sets the time we'll wait for the peer to send its ID during authentication.
If not set, a default of 1000 milliseconds (1 second) will be used.
| void Dwm::Credence::Peer::SetKeyExchangeTimeout | ( | std::chrono::milliseconds | ms | ) |
Sets the time we'll wait for the peer to send its public key.
If not set, a default of 1000 milliseconds (1 second) will be used.