FREEDM DGI
CProtocolSR.hpp
Go to the documentation of this file.
1 
24 #ifndef CPROTOCOLSR_HPP
25 #define CPROTOCOLSR_HPP
26 
27 #include "IProtocol.hpp"
28 
29 #include "messages/ProtocolMessage.pb.h"
30 
31 #include <deque>
32 
33 #include <boost/asio/deadline_timer.hpp>
34 #include <boost/date_time/posix_time/posix_time.hpp>
35 
36 namespace freedm {
37  namespace broker {
38 
41  : public IProtocol
42 {
43  public:
45  explicit CProtocolSR(std::string uuid, boost::asio::ip::udp::endpoint endpoint);
47  void Send(const ModuleMessage& msg);
49  void ReceiveACK(const ProtocolMessage& msg);
51  bool Receive(const ProtocolMessage& msg);
53  void OnReceive();
55  void SendACK(const ProtocolMessage& msg);
57  void SendSYN();
59  void Stop() { m_timeout.cancel(); SetStopped(true); };
61  void Write(ProtocolMessageWindow & msg);
63  void WriteWindow();
64  private:
66  void Resend(const boost::system::error_code& err);
68  boost::asio::deadline_timer m_timeout;
70  unsigned int m_inseq;
72  unsigned int m_outseq;
74  bool m_insync;
76  unsigned int m_inresyncs;
78  boost::posix_time::ptime m_insynctime;
80  bool m_outsync;
82  google::protobuf::uint64 m_outsynchash;
86  unsigned int m_sendkill;
88  std::deque<ProtocolMessage> m_window;
89  std::deque<ProtocolMessage> m_ack_window;
91  static const unsigned int SEQUENCE_MODULO = 1024;
93  static const unsigned int REFIRE_TIME = 10;
95  static const unsigned int MAX_DROPPED_MSGS = 3;
97  unsigned int m_dropped;
100 };
101 
102  }
103 }
104 #endif
std::deque< ProtocolMessage > m_ack_window
Definition: CProtocolSR.hpp:89
boost::asio::deadline_timer m_timeout
Timeout for resends.
Definition: CProtocolSR.hpp:68
google::protobuf::uint64 m_outsynchash
Keeps track of the last resync that we&#39;ve seen.
Definition: CProtocolSR.hpp:82
unsigned int m_inresyncs
Counts the number of times this one has been resynced.
Definition: CProtocolSR.hpp:76
CProtocolSR(std::string uuid, boost::asio::ip::udp::endpoint endpoint)
Initializes the protocol with the underlying connection.
Definition: CProtocolSR.cpp:60
A connection protocol.
Definition: IProtocol.hpp:43
unsigned int m_inseq
The expected next in sequence number.
Definition: CProtocolSR.hpp:70
bool m_insync
Marks if this has been synced.
Definition: CProtocolSR.hpp:74
bool m_sendkills
Marks if we should send the kill hash.
Definition: CProtocolSR.hpp:84
static const unsigned int SEQUENCE_MODULO
Sequence modulo.
Definition: CProtocolSR.hpp:91
void ReceiveACK(const ProtocolMessage &msg)
Public facing function that handles marking down ACKs for sent messages.
Definition: CProtocolSR.cpp:221
A reliable connection protocol with sweet as expirations.
Definition: CProtocolSR.hpp:40
unsigned int m_sendkill
The hash to... MURDER.
Definition: CProtocolSR.hpp:86
void WriteWindow()
Writes a whole window to the channel.
Definition: CProtocolSR.cpp:469
void SendSYN()
Sends a synchronizer.
Definition: CProtocolSR.cpp:413
unsigned int m_dropped
The number that have been dropped.
Definition: CProtocolSR.hpp:97
static const unsigned int MAX_DROPPED_MSGS
The number of messages that have to be dropped before the connection is dead.
Definition: CProtocolSR.hpp:95
bool m_outsync
Marks if we&#39;ve sent the outsync for this connection.
Definition: CProtocolSR.hpp:80
bool m_timer_active
Indicates if the timer is active.
Definition: CProtocolSR.hpp:99
std::deque< ProtocolMessage > m_window
The window.
Definition: CProtocolSR.hpp:88
void Send(const ModuleMessage &msg)
Public facing send function that sends a message.
Definition: CProtocolSR.cpp:95
boost::posix_time::ptime m_insynctime
Time the last accepted sync was.
Definition: CProtocolSR.hpp:78
static const unsigned int REFIRE_TIME
Refire time in MS.
Definition: CProtocolSR.hpp:93
void Write(ProtocolMessageWindow &msg)
Handles writing the message to the underlying connection.
Definition: CProtocolSR.cpp:494
General FREEDM Namespace.
Definition: CBroker.cpp:53
void SetStopped(bool v)
Handles setting the stopped variable.
Definition: IProtocol.hpp:67
bool Receive(const ProtocolMessage &msg)
deterimines if a messageshould be given to the dispatcher
Definition: CProtocolSR.cpp:281
void Stop()
Stops the timers.
Definition: CProtocolSR.hpp:59
void OnReceive()
Writes the window (with acks on message receipt)
Definition: CProtocolSR.cpp:456
void Resend(const boost::system::error_code &err)
Resend outstanding messages.
Definition: CProtocolSR.cpp:141
void SendACK(const ProtocolMessage &msg)
Handles Writing an ack for the input message to the channel.
Definition: CProtocolSR.cpp:393
unsigned int m_outseq
The next number to assign to an outgoing message.
Definition: CProtocolSR.hpp:72