A reliable connection protocol with sweet as expirations.
#include <CProtocolSR.hpp>
|
| CProtocolSR (std::string uuid, boost::asio::ip::udp::endpoint endpoint) |
| Initializes the protocol with the underlying connection. More...
|
|
virtual void | ChangePhase (bool) |
| Handles the change phase even. More...
|
|
int | GetReliability () const |
| Get the connection reliability for DCUSTOMNETWORK. More...
|
|
boost::asio::ip::udp::socket & | GetSocket () |
| Get a socket connected to a single peer DGI. More...
|
|
bool | GetStopped () |
| Handles checking to see if the connection is stopped. More...
|
|
std::string | GetUUID () const |
| Gets the uuid: More...
|
|
void | OnReceive () |
| Writes the window (with acks on message receipt) More...
|
|
bool | Receive (const ProtocolMessage &msg) |
| deterimines if a messageshould be given to the dispatcher More...
|
|
void | ReceiveACK (const ProtocolMessage &msg) |
| Public facing function that handles marking down ACKs for sent messages. More...
|
|
void | Send (const ModuleMessage &msg) |
| Public facing send function that sends a message. More...
|
|
void | SendACK (const ProtocolMessage &msg) |
| Handles Writing an ack for the input message to the channel. More...
|
|
void | SendSYN () |
| Sends a synchronizer. More...
|
|
void | SetReliability (int r) |
| Set the connection reliability for DCUSTOMNETWORK. More...
|
|
void | SetStopped (bool v) |
| Handles setting the stopped variable. More...
|
|
void | Stop () |
| Stops the timers. More...
|
|
void | Write (ProtocolMessageWindow &msg) |
| Handles writing the message to the underlying connection. More...
|
|
void | WriteWindow () |
| Writes a whole window to the channel. More...
|
|
|
virtual void | WriteCallback (const boost::system::error_code &) |
| Callback for when a write completes. More...
|
|
|
void | Resend (const boost::system::error_code &err) |
| Resend outstanding messages. More...
|
|
freedm::broker::CProtocolSR::CProtocolSR |
( |
std::string |
uuid, |
|
|
boost::asio::ip::udp::endpoint |
endpoint |
|
) |
| |
|
explicit |
CProtocolSR::CProtocolSR
- Description:
- Constructor for the CProtocolSR class.
- Precondition:
- The object is uninitialized.
- Postcondition:
- The object is initialized: m_killwindow is empty, the connection is marked as unsynced, It won't be sending kill statuses. Its first message will be numbered as 0 for outgoing and the timer is not set.
- Parameters
-
uuid | The peer this connection is made to. |
endpoint | The endpoint that will be the destination for sent messages |
virtual void freedm::broker::IProtocol::ChangePhase |
( |
bool |
| ) |
|
|
inlinevirtualinherited |
int freedm::broker::IProtocol::GetReliability |
( |
| ) |
const |
|
inherited |
IProtocol::GetReliability
- Description:
- Get the connection reliability for DCUSTOMNETWORK
- Precondition:
- None
- Postcondition:
- None
- Returns
- percentage of packets that are allowed through
boost::asio::ip::udp::socket& freedm::broker::IProtocol::GetSocket |
( |
| ) |
|
|
inherited |
bool freedm::broker::IProtocol::GetStopped |
( |
| ) |
|
|
inlineinherited |
std::string freedm::broker::IProtocol::GetUUID |
( |
| ) |
const |
|
inherited |
IProtocol::GetUUID
- Description:
- Gets the UUID of the DGI on the other end of this connection.
- Precondition:
- None
- Postcondition:
- None
- Returns
- the peer's UUID
void freedm::broker::CProtocolSR::OnReceive |
( |
| ) |
|
|
virtual |
CProtocolSR::OnReceive
- Description:
- When a message is received, write the window to the channel, then flush the ack queue.
- Precondition:
- None
- Postcondition:
- There are no acks queued and the message has been written to the channel.
Implements freedm::broker::IProtocol.
bool freedm::broker::CProtocolSR::Receive |
( |
const ProtocolMessage & |
msg | ) |
|
|
virtual |
CProtocolSR::Receive
- Description:
- Accepts a message into the protocol, if that message should be accepted. If this function returns true, the message is passed to the dispatcher. Since this message accepts SYNs there might be times when processing and state changes but the message is marked as "rejected" this is normal.
- Precondition:
- Accept logic can be complicated, there are several scenarios that should be addressed. 1) A bad request has been received 2) A SYN message is received for the first time 3) A SYN message is received as a duplicate. 4) A Message has been received before the connection has been synced. 5) A Message has been received with the expected sequenceno with or without a kill flag. 6) A message has been received with a kill flag. The kill is greater than the expected sequence number 7) A message has been received with a kill flag. The kill is less than the expected sequence number. However, the message's number is less than the expected sequence number 8) A message has been received with a kill flag. The kill is less than the expected sequence number and the message's sequence number is greater than the expected sequence number.
- Postcondition:
- Cases are handled as follows: 1) The connection is resynced. 2) The message is ACKed, the send time of the sync is noted, and the connection is synced. 3) The SYN is ignored. 4) A bad request message is generated and sent to the source. 5) The message is accepted. 6) The message is rejected. Kills should only ever be less than the expected sequence number unless the message is arrived out of order 7) The message is simply old but still arriving at the socket, and can be rejected. 8) The message should be accepted because one or more message expired in the gap of sequence numbers.
- Parameters
-
- Returns
- True if the message is accepted, false otherwise.
Implements freedm::broker::IProtocol.
void freedm::broker::CProtocolSR::ReceiveACK |
( |
const ProtocolMessage & |
msg | ) |
|
|
virtual |
CProtocolSR::ReceiveACK
- Description:
- Marks a message as acknowledged by the receiver and moves to transmit the next message.
- Precondition:
- A message has been sent.
- Postcondition:
- If the ACK corresponds to the head of window by a match of sequence number and the message hash, the the message is popped and the killable flag is set to false, since the head of the window has never been sent. If the there is still an message in the window to send, the resend function is called.
- Parameters
-
msg | The received ACK message |
Implements freedm::broker::IProtocol.
void freedm::broker::CProtocolSR::Resend |
( |
const boost::system::error_code & |
err | ) |
|
|
private |
CProtocolSR::CProtocolSR
- Description:
- Handles refiring ACKs and Sent Messages.
- Precondition:
- The connection has received or sent at least one message.
- Postcondition:
- One of the following conditions or combination of states is upheld: 1) An ack for a message that has not yet expired has been resent and a timer to call resend has been set. 2) Message(s) has/have expired and are removed from the queue. The flag to send kills is set. 3) The window is empty and no message is set to the channel, the timer is not re-set. 4) A message expired and then next message will cause the sequence numbers to wrap, (or they have wrapped since the last time a message was successfully sent) so a sync is inserted at the front of the queue to skip that case on the receiver side. The sendkill flag is cleared and the sendkill value is cleared. 5) If there is still a message to resend, the timer is reset.
- Parameters
-
err | The timer error code. If the err is 0 then the timer expired |
We use static pointer cast to convert the IPROTOCOL pointer to this derived type
void freedm::broker::CProtocolSR::Send |
( |
const ModuleMessage & |
msg | ) |
|
|
virtual |
CProtocolSR::CProtocolSR
- Description:
- Send function for the CProtocolSR. Sending using this protocol involves an alternating bit scheme. Messages can expire and delivery won't be attempted after the deadline is passed. Killed messages are noted in the next outgoing message. The receiver tracks the killed messages and uses them to help maintain ordering.
- Precondition:
- The protocol is intialized.
- Postcondition:
- At least one message is in the channel and actively being resent. The send window is greater than or equal to one. The timer for the resend is freshly set or is currently running for a resend. If a message is written to the channel, the m_killable flag is set.
- Parameters
-
msg | The message to write to the channel. |
Implements freedm::broker::IProtocol.
void freedm::broker::CProtocolSR::SendACK |
( |
const ProtocolMessage & |
msg | ) |
|
|
virtual |
CProtocolSR::SendACK
- Description:
- Composes an ack and PrepareAndWrites it to the channel. ACKS are saved to the protocol's state and are written again during resends to try and maximize througput.
- Parameters
-
- Precondition:
- A message has been accepted.
- Postcondition:
- The m_currentack member is set to the ack and the message will be resent during resend until it expires.
Implements freedm::broker::IProtocol.
void freedm::broker::CProtocolSR::SendSYN |
( |
| ) |
|
CProtocolSR::SendSYN
- Description:
- Composes an SYN and writes it to the channel.
- Precondition:
- A message has been accepted.
- Postcondition:
- A syn has been written to the channel
void freedm::broker::IProtocol::SetReliability |
( |
int |
r | ) |
|
|
inherited |
IProtocol::SetReliability
- Description:
- Set the connection reliability for DCUSTOMNETWORK. 0 all packets areartifically dropped. 100 means no packets are artifically dropped.
- Precondition:
- None
- Postcondition:
- Sets the reliabilty of the protocol to r
- Parameters
-
void freedm::broker::IProtocol::SetStopped |
( |
bool |
v | ) |
|
|
inlineinherited |
void freedm::broker::CProtocolSR::Stop |
( |
| ) |
|
|
inlinevirtual |
void freedm::broker::CProtocolSR::Write |
( |
ProtocolMessageWindow & |
msg | ) |
|
|
virtual |
CProtocolSR::Write
- Description:
- Writes the message to the connected peer. Also, timestamps the message, if a timestamp does not already exist.
- Precondition:
- None
- Postcondition:
- Writes the message to the channel.
- Parameters
-
Reimplemented from freedm::broker::IProtocol.
virtual void freedm::broker::IProtocol::WriteCallback |
( |
const boost::system::error_code & |
| ) |
|
|
inlineprotectedvirtualinherited |
void freedm::broker::CProtocolSR::WriteWindow |
( |
| ) |
|
CProtocolSR::WriteWindow
- Description:
- Creates a message bundle of outstanding messages to write to the channel.
- Precondition:
- None
- Postcondition:
- Writes the window to the channel.
std::deque<ProtocolMessage> freedm::broker::CProtocolSR::m_ack_window |
|
private |
unsigned int freedm::broker::CProtocolSR::m_dropped |
|
private |
unsigned int freedm::broker::CProtocolSR::m_inresyncs |
|
private |
unsigned int freedm::broker::CProtocolSR::m_inseq |
|
private |
bool freedm::broker::CProtocolSR::m_insync |
|
private |
boost::posix_time::ptime freedm::broker::CProtocolSR::m_insynctime |
|
private |
unsigned int freedm::broker::CProtocolSR::m_outseq |
|
private |
bool freedm::broker::CProtocolSR::m_outsync |
|
private |
google::protobuf::uint64 freedm::broker::CProtocolSR::m_outsynchash |
|
private |
unsigned int freedm::broker::CProtocolSR::m_sendkill |
|
private |
bool freedm::broker::CProtocolSR::m_sendkills |
|
private |
boost::asio::deadline_timer freedm::broker::CProtocolSR::m_timeout |
|
private |
bool freedm::broker::CProtocolSR::m_timer_active |
|
private |
std::deque<ProtocolMessage> freedm::broker::CProtocolSR::m_window |
|
private |
const unsigned int freedm::broker::CProtocolSR::MAX_DROPPED_MSGS = 3 |
|
staticprivate |
const unsigned int freedm::broker::CProtocolSR::REFIRE_TIME = 10 |
|
staticprivate |
const unsigned int freedm::broker::CProtocolSR::SEQUENCE_MODULO = 1024 |
|
staticprivate |
The documentation for this class was generated from the following files:
- /home/docs/checkouts/readthedocs.org/user_builds/freedm/checkouts/latest/Broker/src/CProtocolSR.hpp
- /home/docs/checkouts/readthedocs.org/user_builds/freedm/checkouts/latest/Broker/src/CProtocolSR.cpp