42#ifndef _DWMCREDENCEPEER_HH_
43#define _DWMCREDENCEPEER_HH_
46#include <boost/asio.hpp>
48#include "DwmStreamIO.hh"
49#include "DwmSysLogger.hh"
88 bool Accept(boost::asio::ip::tcp::socket && s);
96 bool Accept(boost::asio::local::stream_protocol::socket && s);
103 bool Connect(
const std::string & host, uint16_t port,
104 std::chrono::milliseconds timeOut = std::chrono::milliseconds(5000));
112 std::chrono::milliseconds timeOut = std::chrono::milliseconds(5000));
136 const std::string &
Id()
const {
return _theirId; }
145 template <
typename T>
155 Syslog(LOG_ERR,
"Failed to flush encrypted stream to %s",
160 Syslog(LOG_ERR,
"Failed to send message to %s",
165 Syslog(LOG_ERR,
"Invalid encrypted output stream");
177 template <
typename T>
186 Syslog(LOG_DEBUG,
"Failed to receive message from %s",
191 Syslog(LOG_ERR,
"Invalid encrypted input stream");
213 std::chrono::milliseconds _keyExchangeTimeout;
214 std::chrono::milliseconds _idExchangeTimeout;
215 boost::asio::ip::tcp::endpoint _endPoint;
216 boost::asio::local::stream_protocol::endpoint _lendPoint;
217 std::string _theirId;
218 std::string _agreedKey;
219 std::unique_ptr<boost::asio::ip::tcp::iostream> _ios;
220 std::unique_ptr<boost::asio::local::stream_protocol::iostream> _lios;
221 std::unique_ptr<XChaCha20Poly1305::Istream> _xis;
222 std::unique_ptr<XChaCha20Poly1305::Ostream> _xos;
Dwm::Credence::KeyStash class declaration.
Dwm::Credence::KnownKeys class declaration.
Dwm::Credence::XChaCha20Poly1305::Istream class declaration.
Dwm::Credence::XChaCha20Poly1305::Ostream class declaration.
Encapsulates storage of an Ed25519KeyPair in a filesystem.
Definition DwmCredenceKeyStash.hh:56
Encapsulates the storage of a set of known public keys.
Definition DwmCredenceKnownKeys.hh:60
Encapsulate a network peer.
Definition DwmCredencePeer.hh:68
bool Send(const T &msg)
Sends the given msg to the peer.
Definition DwmCredencePeer.hh:146
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.
void SetIdExchangeTimeout(std::chrono::milliseconds ms)
Sets the time we'll wait for the peer to send its ID during authentication.
void SetKeyExchangeTimeout(std::chrono::milliseconds ms)
Sets the time we'll wait for the peer to send its public key.
Peer()
Default constructor.
bool Accept(boost::asio::ip::tcp::socket &&s)
Used by a server to accept a new connection on the given TCP socket s.
bool Receive(T &msg)
Receives the given msg from the peer.
Definition DwmCredencePeer.hh:178
const std::string & Id() const
If Authenticate() was used, returns the peer's identifier.
Definition DwmCredencePeer.hh:136
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.
std::string EndPointString() const
Returns a string representation of the peer endpoint, in 'addr:port' form.
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.
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 i...
bool ReceiveWouldBlock(size_t numBytes)
Returns true if a Receive() of numBytes or greater would block.
void Disconnect()
Disconnects the peer.
static std::istream & Read(std::istream &is, char &c)
static std::ostream & Write(std::ostream &os, char c)