ServerPeer
ServerPeer
#include <icy/symple/server.h>Per-connection state for a connected Symple peer.
Created by the server after successful authentication. Holds the peer data, room memberships, and a reference to the underlying WebSocket connection for sending.
Public Methods
| Return | Name | Description |
|---|---|---|
ServerPeer | Constructs a peer bound to the given server-side connection. | |
void | send | Serialises and sends a JSON message over the WebSocket connection. Logs a warning if the send fails; does not throw. |
void | sendSerialized | Sends a pre-serialized JSON payload over the WebSocket connection. Use this on fanout paths that already serialized once. |
void | join | Adds this peer to the named room (local tracking only). |
void | leave | Removes this peer from the named room (local tracking only). |
void | leaveAll | Removes this peer from all rooms (local tracking only). |
Peer & | peer inline | Returns a mutable reference to the peer data object. |
const Peer & | peer const inline | Returns a const reference to the peer data object. |
std::string | id const | Returns the session ID assigned to this peer. |
const std::unordered_set< std::string > & | rooms const inline | Returns the set of room names this peer is currently joined to. |
bool | authenticated const inline | Returns true if the peer has completed authentication. |
void | setAuthenticated inline | Marks the peer as authenticated or unauthenticated. |
void | setPeer inline | Replaces the peer's data object. |
http::ServerConnection & | connection inline | Returns a reference to the underlying server connection. |
bool | checkRate inline | Per-peer rate limiter. Returns false if message should be dropped. |
void | setRateLimit inline | Configures the per-peer rate limit. |
ServerPeer
ServerPeer(http::ServerConnection & conn)Constructs a peer bound to the given server-side connection.
Parameters
connThe underlying WebSocket server connection.
send
void send(const json::Value & msg)Serialises and sends a JSON message over the WebSocket connection. Logs a warning if the send fails; does not throw.
Parameters
msgJSON value to send.
sendSerialized
void sendSerialized(const char * data, size_t len)Sends a pre-serialized JSON payload over the WebSocket connection. Use this on fanout paths that already serialized once.
join
void join(const std::string & room)Adds this peer to the named room (local tracking only).
Parameters
roomRoom name to join.
leave
void leave(const std::string & room)Removes this peer from the named room (local tracking only).
Parameters
roomRoom name to leave.
leaveAll
void leaveAll()Removes this peer from all rooms (local tracking only).
peer
inline
inline Peer & peer()Returns a mutable reference to the peer data object.
peer
const inline
inline const Peer & peer() constReturns a const reference to the peer data object.
id
const
std::string id() constReturns the session ID assigned to this peer.
rooms
const inline
inline const std::unordered_set< std::string > & rooms() constReturns the set of room names this peer is currently joined to.
authenticated
const inline
inline bool authenticated() constReturns true if the peer has completed authentication.
setAuthenticated
inline
inline void setAuthenticated(bool v)Marks the peer as authenticated or unauthenticated.
Parameters
vTrue to mark as authenticated.
setPeer
inline
inline void setPeer(const Peer & p)Replaces the peer's data object.
Parameters
pNew peer data.
connection
inline
inline http::ServerConnection & connection()Returns a reference to the underlying server connection.
checkRate
inline
inline bool checkRate()Per-peer rate limiter. Returns false if message should be dropped.
setRateLimit
inline
inline void setRateLimit(double rate, double seconds)Configures the per-peer rate limit.
Parameters
rateMaximum messages allowed per window.secondsDuration of the rate window in seconds.
Private Attributes
| Return | Name | Description |
|---|---|---|
http::ServerConnection & | _conn | |
Peer | _peer | |
std::unordered_set< std::string > | _rooms | |
RateLimiter | _rateLimiter | 100 messages per 10 seconds default |
bool | _authenticated |
_conn
http::ServerConnection & _conn_peer
Peer _peer_rooms
std::unordered_set< std::string > _rooms_rateLimiter
RateLimiter _rateLimiter {100.0, 10.0}100 messages per 10 seconds default
_authenticated
bool _authenticated = false