OpenSDN source code
xmpp_state_machine.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
7 
8 #include <atomic>
9 #include <typeinfo>
10 #include <boost/bind/bind.hpp>
11 #include <boost/date_time/posix_time/posix_time.hpp>
12 #include <boost/statechart/custom_reaction.hpp>
13 #include <boost/statechart/event.hpp>
14 #include <boost/statechart/simple_state.hpp>
15 #include <boost/statechart/state.hpp>
16 #include <boost/statechart/state_machine.hpp>
17 #include <boost/statechart/transition.hpp>
18 
19 #include "base/logging.h"
20 #include "base/task_annotations.h"
21 #include "io/event_manager.h"
22 #include "io/ssl_session.h"
23 #include "sandesh/sandesh_trace.h"
24 #include "sandesh/common/vns_types.h"
25 #include "sandesh/common/vns_constants.h"
26 #include "sandesh/xmpp_client_server_sandesh_types.h"
27 #include "sandesh/xmpp_peer_info_types.h"
28 #include "sandesh/xmpp_state_machine_sandesh_types.h"
29 #include "sandesh/xmpp_trace_sandesh_types.h"
30 #include "xmpp/xmpp_connection.h"
31 #include "xmpp/xmpp_factory.h"
32 #include "xmpp/xmpp_log.h"
33 #include "xmpp/xmpp_server.h"
34 #include "xmpp/xmpp_session.h"
35 
36 using namespace std;
37 using namespace boost::placeholders;
38 
39 namespace mpl = boost::mpl;
40 namespace sc = boost::statechart;
41 
42 #define SM_LOG(_sm, _msg) do { \
43  XMPP_UTDEBUG(XmppStateMachineDebug, \
44  (_sm)->connection() ? (_sm)->connection()->ToUVEKey() : "", \
45  XMPP_PEER_DIR_NA, (_sm)->ChannelType(), _msg); \
46 } while (false)
47 
48 namespace xmsm {
49 // events
50 
51 struct EvStart : sc::event<EvStart> {
52  static const char *Name() {
53  return "EvStart";
54  }
55 };
56 
57 struct EvStop : sc::event<EvStop> {
58  static const char *Name() {
59  return "EvStop";
60  }
61 };
62 
63 struct EvAdminDown : sc::event<EvAdminDown> {
64  static const char *Name() {
65  return "EvAdminDown";
66  }
67 };
68 
69 struct EvConnectTimerExpired : sc::event<EvConnectTimerExpired> {
70  static const char *Name() {
71  return "EvConnectTimerExpired";
72  }
73 };
74 
75 struct EvOpenTimerExpired : sc::event<EvOpenTimerExpired> {
76  static const char *Name() {
77  return "EvOpenTimerExpired";
78  }
79 };
80 
81 struct EvHoldTimerExpired : sc::event<EvHoldTimerExpired> {
82  static const char *Name() {
83  return "EvHoldTimerExpired";
84  }
85 };
86 
87 struct EvTcpConnected : sc::event<EvTcpConnected> {
88  EvTcpConnected(XmppSession *session) : session(session) { };
89  static const char *Name() {
90  return "EvTcpConnected";
91  }
93 } ;
94 
95 struct EvTcpConnectFail : sc::event<EvTcpConnectFail> {
96  EvTcpConnectFail(XmppSession *session) : session(session) { };
97  static const char *Name() {
98  return "EvTcpConnectFail";
99  }
101 } ;
102 
103 struct EvTcpPassiveOpen : sc::event<EvTcpPassiveOpen> {
104  EvTcpPassiveOpen(XmppSession *session) : session(session) { };
105  static const char *Name() {
106  return "EvTcpPassiveOpen";
107  }
109 };
110 
111 struct EvTcpClose : sc::event<EvTcpClose> {
112  EvTcpClose(XmppSession *session) : session(session) { };
113  static const char *Name() {
114  return "EvTcpClose";
115  }
117 };
118 
119 struct EvTcpDeleteSession : sc::event<EvTcpDeleteSession> {
120  explicit EvTcpDeleteSession(TcpSession *session) : session(session) { }
121  static const char *Name() {
122  return "EvTcpDeleteSession";
123  }
125 };
126 
127 struct EvXmppMessage : sc::event<EvXmppMessage> {
128  explicit EvXmppMessage(XmppSession *session,
129  const XmppStanza::XmppMessage *msg) : session(session), msg(msg) { }
130  static const char *Name() {
131  return "EvXmppMessage";
132  }
135 };
136 
137 struct EvXmppOpen : public sc::event<EvXmppOpen> {
139  session(session),
140  msg(static_cast<const XmppStanza::XmppStreamMessage *>(msg)) {
141  }
142  static const char *Name() {
143  return "EvXmppOpen";
144  }
146  boost::shared_ptr<const XmppStanza::XmppStreamMessage> msg;
147 };
148 
149 struct EvStreamFeatureRequest : sc::event<EvStreamFeatureRequest> {
151  const XmppStanza::XmppMessage *msg) :
152  session(session),
153  msg(static_cast<const XmppStanza::XmppStreamMessage *>(msg)) {
154  }
155  static const char *Name() {
156  return "EvStreamFeatureRequest";
157  }
159  boost::shared_ptr<const XmppStanza::XmppMessage> msg;
160 };
161 
162 struct EvStartTls : sc::event<EvStartTls> {
164  const XmppStanza::XmppMessage *msg) :
165  session(session),
166  msg(static_cast<const XmppStanza::XmppStreamMessage *>(msg)) {
167  }
168  static const char *Name() {
169  return "EvStartTls";
170  }
172  boost::shared_ptr<const XmppStanza::XmppMessage> msg;
173 };
174 
175 struct EvTlsProceed : sc::event<EvTlsProceed> {
177  const XmppStanza::XmppMessage *msg) :
178  session(session),
179  msg(static_cast<const XmppStanza::XmppStreamMessage *>(msg)) {
180  }
181  static const char *Name() {
182  return "EvTlsProceed";
183  }
185  boost::shared_ptr<const XmppStanza::XmppMessage> msg;
186 };
187 
188 struct EvTlsHandShakeSuccess : sc::event<EvTlsHandShakeSuccess> {
189  explicit EvTlsHandShakeSuccess(XmppSession *session) :
190  session(session) { }
191  static const char *Name() {
192  return "EvTlsHandShakeSuccess";
193  }
195 };
196 
197 struct EvTlsHandShakeFailure : sc::event<EvTlsHandShakeFailure> {
198  explicit EvTlsHandShakeFailure(XmppSession *session) :
199  session(session) { }
200  static const char *Name() {
201  return "EvTlsHandShakeFailure";
202  }
204 };
205 
206 struct EvXmppKeepalive : sc::event<EvXmppKeepalive> {
208  const XmppStanza::XmppMessage *msg) :
209  session(session), msg(msg) {
210  }
211  static const char *Name() {
212  return "EvXmppKeepalive";
213  }
215  boost::shared_ptr<const XmppStanza::XmppMessage> msg;
216 };
217 
218 struct EvXmppMessageStanza : sc::event<EvXmppMessageStanza> {
220  const XmppStanza::XmppMessage *msg) :
221  session(session), msg(msg) {
222  }
223  static const char *Name() {
224  return "EvXmppMessageStanza";
225  }
227  boost::shared_ptr<const XmppStanza::XmppMessage> msg;
228 };
229 
230 struct EvXmppIqStanza : sc::event<EvXmppIqStanza> {
232  const XmppStanza::XmppMessage *msg)
233  : session(session), msg(msg) {
234  }
235  static const char *Name() {
236  return "EvXmppIqStanza";
237  }
239  boost::shared_ptr<const XmppStanza::XmppMessage> msg;
240 };
241 
242 struct EvXmppOpenReceive : sc::event<EvXmppOpenReceive> {
243  EvXmppOpenReceive(XmppSession *session) : session(session) {
244  }
245  static const char *Name() {
246  return "EvXmppOpenReceive";
247  }
249 };
250 
251 struct Idle : public sc::state<Idle, XmppStateMachine> {
252  typedef sc::transition<EvStart, Active,
254  Idle(my_context ctx) : my_base(ctx) {
255  XmppStateMachine *state_machine = &context<XmppStateMachine>();
256  bool flap = (state_machine->get_state() == ESTABLISHED);
257  state_machine->set_state(IDLE);
258  state_machine->SendConnectionInfo("Start", "Active");
259  if (flap) {
260  state_machine->connection()->increment_flap_count();
261  }
262  }
263 };
264 
265 struct Active : public sc::state<Active, XmppStateMachine> {
266  typedef mpl::list<
267  sc::custom_reaction<EvAdminDown>,
268  sc::custom_reaction<EvConnectTimerExpired>,
269  sc::custom_reaction<EvOpenTimerExpired>,
270  sc::custom_reaction<EvTcpPassiveOpen>,
271  sc::custom_reaction<EvTcpClose>,
272  sc::custom_reaction<EvXmppOpen>,
273  sc::custom_reaction<EvStop>
275 
276  Active(my_context ctx) : my_base(ctx) {
277  XmppStateMachine *state_machine = &context<XmppStateMachine>();
278  state_machine->keepalive_count_clear();
279  bool flap = (state_machine->get_state() == ESTABLISHED);
280  state_machine->set_state(ACTIVE);
281  if (flap) {
282  state_machine->connection()->increment_flap_count();
283  }
284  if (state_machine->IsActiveChannel() ) {
285  if (state_machine->get_connect_attempts() >=
287  XmppConnection *connection = state_machine->connection();
288  if (connection) {
289  state_machine->SendConnectionInfo(
290  "Connect failed after retries");
291  // Notify clients if any action to be taken
292  connection->ChannelMux()->HandleStateEvent(xmsm::ACTIVE);
293  }
294  }
295  state_machine->StartConnectTimer(state_machine->GetConnectTime());
296  }
297  }
299  XmppStateMachine *state_machine = &context<XmppStateMachine>();
300  state_machine->CancelConnectTimer();
301  state_machine->CancelOpenTimer();
302  }
303 
304  //event on client only
305  sc::result react(const EvConnectTimerExpired &event) {
306  XmppStateMachine *state_machine = &context<XmppStateMachine>();
307  if (state_machine->ConnectTimerCancelled()) {
308  SM_LOG(state_machine, "Discard EvConnectTimerExpired in (Active) State");
309  return discard_event();
310  } else {
311  state_machine->SendConnectionInfo(event.Name(), "Connect");
312  SM_LOG(state_machine, "EvConnectTimerExpired in (Active) State");
313  return transit<Connect>();
314  }
315  }
316 
317  // event on server only
318  sc::result react(const EvTcpPassiveOpen &event) {
319  XmppStateMachine *state_machine = &context<XmppStateMachine>();
320  event.session->AsyncReadStart();
321  assert(state_machine->session() == event.session);
322  event.session->set_observer(
324  state_machine, _1, _2));
326  XmppConnectionInfo info;
327  info.set_local_port(event.session->local_port());
328  info.set_remote_port(event.session->remote_port());
329  state_machine->SendConnectionInfo(&info, event.Name());
330  return discard_event();
331  }
332 
333  // event on server only
334  sc::result react(const EvTcpClose &event) {
335  XmppStateMachine *state_machine = &context<XmppStateMachine>();
336  if (event.session != state_machine->session()) {
337  return discard_event();
338  }
339  state_machine->CancelOpenTimer();
340  state_machine->ResetSession();
341  state_machine->SendConnectionInfo(event.Name(), "Idle");
342  return transit<Idle>();
343  }
344 
345  //event on server only
346  sc::result react(const EvOpenTimerExpired &event) {
347  XmppStateMachine *state_machine = &context<XmppStateMachine>();
348  if (state_machine->OpenTimerCancelled()) {
349  SM_LOG(state_machine,
350  "Discard EvOpenTimerExpired in (Active) State");
351  return discard_event();
352  }
353 
354  // At this point session on connection is not set, hence SendClose
355  // using session on the state_machine.
356  XmppSession *session = state_machine->session();
357  XmppConnection *connection = state_machine->connection();
358  connection->SendClose(session);
359  state_machine->ResetSession();
360  state_machine->SendConnectionInfo(event.Name(), "Idle");
361  return transit<Idle>();
362  }
363 
364  //event on server only
365  sc::result react(const EvXmppOpen &event) {
366  XmppStateMachine *state_machine = &context<XmppStateMachine>();
367  if (event.session != state_machine->session()) {
368  return discard_event();
369  }
370  state_machine->AssignSession();
371 
372  XmppConnection *connection = state_machine->connection();
373  if (connection->IsDeleted()) {
374  state_machine->ResetSession();
375  return discard_event();
376  }
377 
378  XmppSession *session = state_machine->session();
379  if (!state_machine->IsAuthEnabled())
380  state_machine->ResurrectOldConnection(connection, session);
381 
382  // Get the possibly updated XmppConnection information.
383  connection = state_machine->connection();
384  state_machine->CancelOpenTimer();
385  if (!connection->SendOpenConfirm(session)) {
386  connection->SendClose(session);
387  state_machine->ResetSession();
388  state_machine->SendConnectionInfo("Send Open Confirm Failed",
389  "Idle");
390  return transit<Idle>();
391  } else {
392  XmppConnectionInfo info;
393  info.set_identifier(event.msg->from);
394  if (state_machine->IsAuthEnabled()) {
395  state_machine->SendConnectionInfo(&info, event.Name(),
396  "Open Confirm");
397  return transit<OpenConfirm>();
398  } else {
399  connection->StartKeepAliveTimer();
400  state_machine->SendConnectionInfo(&info, event.Name(),
401  "Established");
402  return transit<XmppStreamEstablished>();
403  }
404  }
405  }
406 
407  sc::result react(const EvStop &event) {
408  XmppStateMachine *state_machine = &context<XmppStateMachine>();
409  XmppConnection *connection = state_machine->connection();
410  state_machine->CancelOpenTimer();
411  state_machine->CancelConnectTimer();
412  connection->StopKeepAliveTimer();
413 
414  if (state_machine->IsActiveChannel() ) {
415  state_machine->set_session(NULL);
416  state_machine->SendConnectionInfo(event.Name(), "Active");
417  return transit<Active>();
418  } else {
419  state_machine->ResetSession();
420  state_machine->SendConnectionInfo(event.Name(), "Idle");
421  return transit<Idle>();
422  }
423  }
424 
425  sc::result react(const EvAdminDown &event) {
426  XmppStateMachine *state_machine = &context<XmppStateMachine>();
427  XmppConnectionInfo info;
428  info.set_close_reason("Administratively down");
429  state_machine->connection()->set_close_reason("Administratively down");
430  state_machine->SendConnectionInfo(&info, event.Name(), "Idle");
431  return transit<Idle>();
432  }
433 
434 };
435 
436 //State valid only for client side, connection in Active state
437 struct Connect : public sc::state<Connect, XmppStateMachine> {
438  typedef mpl::list<
439  sc::custom_reaction<EvAdminDown>,
440  sc::custom_reaction<EvConnectTimerExpired>,
441  sc::custom_reaction<EvTcpConnected>,
442  sc::custom_reaction<EvTcpConnectFail>,
443  sc::custom_reaction<EvTcpClose>,
444  sc::custom_reaction<EvStop>
446 
447  static const int kConnectTimeout = 60; // seconds
448 
449  Connect(my_context ctx) : my_base(ctx) {
450  XmppStateMachine *state_machine = &context<XmppStateMachine>();
451  StartSession(state_machine);
452  state_machine->connect_attempts_inc();
453  state_machine->set_state(CONNECT);
454  state_machine->StartConnectTimer(state_machine->GetConnectTime());
455  XmppSession *session = state_machine->session();
456  if (session != NULL) {
457  XmppConnectionInfo info;
458  info.set_local_port(session->local_port());
459  info.set_remote_port(session->remote_port());
460  state_machine->SendConnectionInfo(&info, "Connect Event");
461  }
462  }
464  XmppStateMachine *state_machine = &context<XmppStateMachine>();
465  state_machine->CancelConnectTimer();
466  }
467 
468  sc::result react(const EvConnectTimerExpired &event) {
469  XmppStateMachine *state_machine = &context<XmppStateMachine>();
470  if (state_machine->ConnectTimerCancelled()) {
471  SM_LOG(state_machine,
472  "Discard EvConnectTimerExpired in (Connect) State");
473  return discard_event();
474  }
475  CloseSession(state_machine);
476  XmppConnectionInfo info;
477  info.set_close_reason("Connect timer expired");
478  state_machine->connection()->set_close_reason("Connect timer expired");
479  state_machine->SendConnectionInfo(&info, event.Name(), "Active");
480  return transit<Active>();
481  }
482 
483  sc::result react(const EvTcpConnected &event) {
484  XmppStateMachine *state_machine = &context<XmppStateMachine>();
485  if (event.session != state_machine->session()) {
486  return discard_event();
487  }
488  XmppConnection *connection = state_machine->connection();
489  state_machine->CancelConnectTimer();
490  XmppSession *session = state_machine->session();
491  XmppConnectionInfo info;
492  info.set_local_port(session->local_port());
493  info.set_remote_port(session->remote_port());
494  if (connection->SendOpen(session)) {
495  state_machine->StartHoldTimer();
496  state_machine->SendConnectionInfo(&info, event.Name(), "OpenSent");
497  return transit<OpenSent>();
498  } else {
499  SM_LOG(state_machine, "SendOpen failed in (Connect) State");
500  CloseSession(state_machine);
501  info.set_close_reason("SendOpen failed");
502  state_machine->connection()->set_close_reason("Send Open failed");
503  state_machine->SendConnectionInfo(&info, "Send Open failed",
504  "Active");
505  return transit<Active>();
506  }
507  }
508 
509  sc::result react(const EvTcpConnectFail &event) {
510  // delete session; restart connect timer.
511  XmppStateMachine *state_machine = &context<XmppStateMachine>();
512  if (event.session != state_machine->session()) {
513  return discard_event();
514  }
515  state_machine->set_session(NULL);
516  state_machine->CancelConnectTimer();
517  state_machine->SendConnectionInfo(event.Name(), "Active");
518  return transit<Active>();
519  }
520 
521  sc::result react(const EvTcpClose &event) {
522  XmppStateMachine *state_machine = &context<XmppStateMachine>();
523  if (event.session != state_machine->session()) {
524  return discard_event();
525  }
526  // close the tcp sessions.
527  CloseSession(state_machine);
528  state_machine->CancelConnectTimer();
529  state_machine->SendConnectionInfo(event.Name(), "Active");
530  return transit<Active>();
531  }
532 
533  sc::result react(const EvStop &event) {
534  XmppStateMachine *state_machine = &context<XmppStateMachine>();
535  CloseSession(state_machine);
536  state_machine->CancelConnectTimer();
537  XmppConnectionInfo info;
538  info.set_close_reason("EvStop received");
539  state_machine->connection()->set_close_reason("EvStop received");
540  state_machine->SendConnectionInfo(&info, event.Name(), "Active");
541  return transit<Active>();
542  }
543 
544  sc::result react(const EvAdminDown &event) {
545  XmppStateMachine *state_machine = &context<XmppStateMachine>();
546  CloseSession(state_machine);
547  XmppConnectionInfo info;
548  info.set_close_reason("Administratively down");
549  state_machine->connection()->set_close_reason("Administratively down");
550  state_machine->SendConnectionInfo(&info, event.Name(), "Idle");
551  return transit<Idle>();
552  }
553 
554  // Create an active connection request.
555  void StartSession(XmppStateMachine *state_machine) {
556  XmppConnection *connection = state_machine->connection();
557  XmppSession *session = connection->CreateSession();
558  state_machine->set_session(session);
559  session->set_observer(boost::bind(&XmppStateMachine::OnSessionEvent,
560  state_machine, _1, _2));
561  boost::system::error_code err;
562  session->socket()->bind(connection->local_endpoint(), err);
563  if (err) {
564  LOG(WARN, "Bind failure for local address " <<
565  connection->local_endpoint() << " : " << err.message());
566  assert(false);
567  }
568  connection->server()->Connect(session, connection->endpoint());
569  }
570 
571  void CloseSession(XmppStateMachine *state_machine) {
572  state_machine->set_session(NULL);
573  }
574 };
575 
576 // The client reaches OpenSent after sending an immediate OPEN on a active
577 // connection. Server should not come in this state.
578 struct OpenSent : public sc::state<OpenSent, XmppStateMachine> {
579  typedef mpl::list<
580  sc::custom_reaction<EvAdminDown>,
581  sc::custom_reaction<EvTcpClose>,
582  sc::custom_reaction<EvXmppOpen>,
583  sc::custom_reaction<EvHoldTimerExpired>,
584  sc::custom_reaction<EvStop>
586 
587  OpenSent(my_context ctx) : my_base(ctx) {
588  XmppStateMachine *state_machine = &context<XmppStateMachine>();
589  state_machine->set_state(OPENSENT);
590  }
592  XmppStateMachine *state_machine = &context<XmppStateMachine>();
593  state_machine->CancelHoldTimer();
594  }
595 
596  sc::result react(const EvTcpClose &event) {
597  XmppStateMachine *state_machine = &context<XmppStateMachine>();
598  if (event.session != state_machine->session()) {
599  return discard_event();
600  }
601  state_machine->CancelHoldTimer();
602  if (event.session) {
603  state_machine->set_session(NULL);
604  state_machine->SendConnectionInfo(event.Name(), "Active");
605  return transit<Active>();
606  }
607  return discard_event();
608  }
609 
610  sc::result react(const EvXmppOpen &event) {
611  XmppStateMachine *state_machine = &context<XmppStateMachine>();
612  XmppConnection *connection = state_machine->connection();
613  if (event.session == state_machine->session()) {
614  state_machine->AssignSession();
615  XmppConnectionInfo info;
616  info.set_identifier(event.msg->from);
617  if (state_machine->IsAuthEnabled()) {
618  state_machine->SendConnectionInfo(&info, event.Name(),
619  "Open Confirm");
620  return transit<OpenConfirm>();
621  } else {
622  connection->SendKeepAlive();
623  connection->StartKeepAliveTimer();
624  state_machine->StartHoldTimer();
625  state_machine->SendConnectionInfo(&info, event.Name(),
626  "Established");
627  return transit<XmppStreamEstablished>();
628  }
629  }
630  return discard_event();
631  }
632 
633  sc::result react(const EvHoldTimerExpired &event) {
634  XmppStateMachine *state_machine = &context<XmppStateMachine>();
635  if (state_machine->HoldTimerCancelled()) {
636  SM_LOG(state_machine,
637  "Discard EvHoldTimerExpired in (OpenSent) State");
638  return discard_event();
639  }
640  CloseSession(state_machine);
641  XmppConnectionInfo info;
642  info.set_close_reason("Hold timer expired");
643  state_machine->connection()->set_close_reason("Hold timer expired");
644  state_machine->SendConnectionInfo(&info, event.Name(), "Active");
645  return transit<Active>();
646  }
647 
648  sc::result react(const EvStop &event) {
649  XmppStateMachine *state_machine = &context<XmppStateMachine>();
650  state_machine->CancelHoldTimer();
651  CloseSession(state_machine);
652  XmppConnectionInfo info;
653  info.set_close_reason("EvStop received");
654  state_machine->connection()->set_close_reason("EvStop received");
655  state_machine->SendConnectionInfo(&info, event.Name(), "Active");
656  return transit<Active>();
657  }
658 
659  sc::result react(const EvAdminDown &event) {
660  XmppStateMachine *state_machine = &context<XmppStateMachine>();
661  CloseSession(state_machine);
662  XmppConnectionInfo info;
663  info.set_close_reason("Administratively down");
664  state_machine->connection()->set_close_reason("Administratively down");
665  state_machine->SendConnectionInfo(&info, event.Name(), "Idle");
666  return transit<Idle>();
667  }
668 
669  void CloseSession(XmppStateMachine *state_machine) {
670  state_machine->set_session(NULL);
671  }
672 };
673 
674 struct OpenConfirm : public sc::state<OpenConfirm, XmppStateMachine> {
675  typedef mpl::list<
676  sc::custom_reaction<EvAdminDown>,
677  sc::custom_reaction<EvTcpClose>,
678  sc::custom_reaction<EvHoldTimerExpired>,
679  sc::custom_reaction<EvStreamFeatureRequest>, //received by client
680  sc::custom_reaction<EvStartTls>, //received by server
681  sc::custom_reaction<EvTlsProceed>, //received by client
682  sc::custom_reaction<EvTlsHandShakeSuccess>,
683  sc::custom_reaction<EvTlsHandShakeFailure>,
684  sc::custom_reaction<EvXmppOpen>, //received by server
685  sc::custom_reaction<EvStop>
687 
688  OpenConfirm(my_context ctx) : my_base(ctx) {
689  XmppStateMachine *state_machine = &context<XmppStateMachine>();
690  state_machine->StartHoldTimer();
691  XmppConnectionInfo info;
692  if (!state_machine->IsActiveChannel()) { //server
693  if (state_machine->IsAuthEnabled()) {
694  XmppConnection *connection = state_machine->connection();
695  XmppSession *session = state_machine->session();
696  if (!connection->SendStreamFeatureRequest(session)) {
697  connection->SendClose(session);
698  SM_LOG(state_machine,
699  "Xmpp Send Stream Feature Request Failed, IDLE");
700  state_machine->ResetSession();
701  info.set_close_reason("Send Stream Feature Request Failed");
702  state_machine->connection()->set_close_reason(
703  "Send Stream Feature Request Failed");
704  state_machine->SendConnectionInfo(&info,
705  "Send Stream Feature Request failed", "Idle");
706  // cannot transition state as this is the constructor
707  // of new state
708  }
709  }
710  }
711  state_machine->set_state(OPENCONFIRM);
712  state_machine->set_openconfirm_state(OPENCONFIRM_INIT);
713  }
714 
715  sc::result react(const EvTcpClose &event) {
716  XmppStateMachine *state_machine = &context<XmppStateMachine>();
717  state_machine->CancelHoldTimer();
718  if (state_machine->IsActiveChannel() ) {
719  CloseSession(state_machine);
720  state_machine->SendConnectionInfo(event.Name(), "Active");
721  return transit<Active>();
722  } else {
723  state_machine->ResetSession();
724  state_machine->SendConnectionInfo(event.Name(), "Idle");
725  return transit<Idle>();
726  }
727  }
728 
729  sc::result react(const EvHoldTimerExpired &event) {
730  XmppStateMachine *state_machine = &context<XmppStateMachine>();
731  if (state_machine->HoldTimerCancelled()) {
732  SM_LOG(state_machine,
733  "Discard EvHoldTimerExpired in (OpenConfirm) State");
734  return discard_event();
735  }
736  XmppConnectionInfo info;
737  info.set_close_reason("Hold timer expired");
738  state_machine->connection()->set_close_reason("Hold timer expired");
739  if (state_machine->IsActiveChannel() ) {
740  CloseSession(state_machine);
741  state_machine->SendConnectionInfo(&info, event.Name(), "Active");
742  return transit<Active>();
743  } else {
744  state_machine->ResetSession();
745  state_machine->SendConnectionInfo(&info, event.Name(), "Idle");
746  return transit<Idle>();
747  }
748  }
749 
750  // received by the client
751  sc::result react(const EvStreamFeatureRequest &event) {
752  XmppStateMachine *state_machine = &context<XmppStateMachine>();
753  XmppConnection *connection = state_machine->connection();
754  XmppSession *session = state_machine->session();
755  // TODO, we need to have a supported stream feature list
756  // and compare against the requested stream feature list
757  // which will enable us to send start of various features
758  if (!connection->SendStartTls(session)) {
759  connection->SendClose(session);
760  state_machine->ResetSession();
761  XmppConnectionInfo info;
762  info.set_close_reason("Send Start Tls Failed");
763  state_machine->SendConnectionInfo(&info, event.Name(), "Active");
764  return transit<Active>();
765  } else {
766  state_machine->StartHoldTimer();
767  state_machine->SendConnectionInfo(event.Name(),
768  "Sent Start Tls, OpenConfirm Feature Negotiation");
769  state_machine->set_openconfirm_state(
771  return discard_event();
772  }
773  }
774 
775  // received by client
776  sc::result react(const EvTlsProceed &event) {
777  XmppStateMachine *state_machine = &context<XmppStateMachine>();
778  XmppConnection *connection = state_machine->connection();
779  XmppSession *session = state_machine->session();
780  state_machine->StartHoldTimer();
781  XmppConnectionInfo info;
782  info.set_identifier(connection->GetTo());
783  // Trigger Ssl Handshake on client side
784  session->TriggerSslHandShake(state_machine->HandShakeCbHandler());
785  state_machine->SendConnectionInfo( &info, event.Name(),
786  "Trigger Client Ssl Handshake");
787  return discard_event();
788  }
789 
790  //received by server
791  sc::result react(const EvStartTls &event) {
792  XmppStateMachine *state_machine = &context<XmppStateMachine>();
793  if (event.session != state_machine->session()) {
794  return discard_event();
795  }
796  XmppConnection *connection = state_machine->connection();
797  XmppSession *session = state_machine->session();
798  XmppConnectionInfo info;
799  info.set_identifier(connection->GetTo());
800  if (!connection->SendProceedTls(session)) {
801  connection->SendClose(session);
802  state_machine->ResetSession();
803  info.set_close_reason("Send Proceed Tls Failed");
804  state_machine->SendConnectionInfo(&info, event.Name(), "Idle");
805  return transit<Idle>();
806  } else {
807  state_machine->StartHoldTimer();
808  // Trigger Ssl Handshake on server side
809  session->TriggerSslHandShake(state_machine->HandShakeCbHandler());
810  state_machine->SendConnectionInfo(&info, event.Name(),
811  "Trigger Server Ssl Handshake");
812  return discard_event();
813  }
814  }
815 
816  sc::result react(const EvStop &event) {
817  XmppStateMachine *state_machine = &context<XmppStateMachine>();
818  state_machine->CancelHoldTimer();
819  if (state_machine->IsActiveChannel() ) {
820  CloseSession(state_machine);
821  state_machine->SendConnectionInfo(event.Name(), "Active");
822  return transit<Active>();
823  } else {
824  state_machine->ResetSession();
825  state_machine->SendConnectionInfo(event.Name(), "Idle");
826  return transit<Idle>();
827  }
828  }
829 
830  sc::result react(const EvTlsHandShakeSuccess &event) {
831  XmppStateMachine *state_machine = &context<XmppStateMachine>();
832  if (event.session != state_machine->session()) {
833  return discard_event();
834  }
835  XmppConnection *connection = state_machine->connection();
836  XmppSession *session = state_machine->session();
837  session->AsyncReadStart();
839  if (state_machine->IsActiveChannel()) { //client
840  if (!connection->SendOpen(session)) {
841  connection->SendClose(session);
842  state_machine->ResetSession();
843  XmppConnectionInfo info;
844  info.set_close_reason("Open send failed in OpenConfirm State");
845  state_machine->SendConnectionInfo(event.Name(), "Active");
846  return transit<Active>();
847  }
848  }
849  // both server and client
850  state_machine->StartHoldTimer();
851  state_machine->SendConnectionInfo(event.Name(),
852  "OpenConfirm Feature Negotiation Success");
853  return discard_event();
854  }
855 
856  sc::result react(const EvTlsHandShakeFailure &event) {
857  XmppStateMachine *state_machine = &context<XmppStateMachine>();
858  if (event.session != state_machine->session()) {
859  return discard_event();
860  }
861  // Do not send stream close as error occured at TLS layer
862  state_machine->ResetSession();
863  if (state_machine->IsActiveChannel()) { // client
864  state_machine->SendConnectionInfo(event.Name(), "Active");
865  return transit<Active>();
866  } else {
867  state_machine->SendConnectionInfo(event.Name(), "Idle");
868  return transit<Idle>();
869  }
870  }
871 
872  //event on server and client
873  sc::result react(const EvXmppOpen &event) {
874  XmppStateMachine *state_machine = &context<XmppStateMachine>();
875  if (event.session != state_machine->session()) {
876  return discard_event();
877  }
878  XmppConnectionInfo info;
879  info.set_identifier(event.msg->from);
880  XmppConnection *connection = state_machine->connection();
881  XmppSession *session = state_machine->session();
882  if (connection->IsActiveChannel()) { //client
883  connection->SendKeepAlive();
884  connection->StartKeepAliveTimer();
885  state_machine->StartHoldTimer();
886  state_machine->SendConnectionInfo(&info, event.Name(),
887  "Established");
888  return transit<XmppStreamEstablished>();
889  } else { //server
890  if (!connection->SendOpenConfirm(session)) {
891  connection->SendClose(session);
892  SM_LOG(state_machine,
893  "Xmpp Send Open Confirm Failed, IDLE");
894  state_machine->ResetSession();
895  info.set_close_reason("Send Open Confirm Failed");
896  state_machine->connection()->set_close_reason(
897  "Send Open Confirm Failed");
898  state_machine->SendConnectionInfo(&info, event.Name(), "Idle");
899  return transit<Idle>();
900  } else {
901  if (state_machine->IsAuthEnabled())
902  state_machine->ResurrectOldConnection(connection, session);
903  connection = state_machine->connection();
904  connection->StartKeepAliveTimer();
905  state_machine->StartHoldTimer();
906  state_machine->SendConnectionInfo(&info, event.Name(),
907  "Established");
908  return transit<XmppStreamEstablished>();
909  }
910  }
911  }
912 
913  sc::result react(const EvAdminDown &event) {
914  XmppStateMachine *state_machine = &context<XmppStateMachine>();
915  CloseSession(state_machine);
916  XmppConnectionInfo info;
917  info.set_close_reason("Administratively down");
918  state_machine->connection()->set_close_reason("Administratively down");
919  state_machine->SendConnectionInfo(&info, event.Name(), "Idle");
920  return transit<Idle>();
921  }
922 
923  void CloseSession(XmppStateMachine *state_machine) {
924  XmppConnection *connection = state_machine->connection();
925  if (connection != NULL) connection->StopKeepAliveTimer();
926  state_machine->set_session(NULL);
927  }
928 };
929 
931  public sc::state<XmppStreamEstablished, XmppStateMachine> {
932  typedef mpl::list<
933  sc::custom_reaction<EvAdminDown>,
934  sc::custom_reaction<EvTcpClose>,
935  sc::custom_reaction<EvXmppKeepalive>,
936  sc::custom_reaction<EvXmppMessageStanza>,
937  sc::custom_reaction<EvXmppIqStanza>,
938  sc::custom_reaction<EvHoldTimerExpired>,
939  sc::custom_reaction<EvStop>
941 
942  XmppStreamEstablished(my_context ctx) : my_base(ctx) {
943  XmppStateMachine *state_machine = &context<XmppStateMachine>();
944  XmppConnection *connection = state_machine->connection();
945  state_machine->StartHoldTimer();
946  state_machine->set_state(ESTABLISHED);
948  }
950  XmppStateMachine *state_machine = &context<XmppStateMachine>();
951  state_machine->CancelHoldTimer();
952  }
953 
954  sc::result react(const EvTcpClose &event) {
955  XmppStateMachine *state_machine = &context<XmppStateMachine>();
956  if (event.session != state_machine->session()) {
957  return discard_event();
958  }
959  state_machine->ResetSession();
960  if (state_machine->IsActiveChannel()) {
961  state_machine->SendConnectionInfo(event.Name(), "Active");
962  return transit<Active>();
963  } else {
964  state_machine->SendConnectionInfo(event.Name(), "Idle");
965  return transit<Idle>();
966  }
967  }
968 
969  sc::result react(const EvXmppKeepalive &event) {
970  XmppStateMachine *state_machine = &context<XmppStateMachine>();
971  if (event.session != state_machine->session()) {
972  return discard_event();
973  }
974  state_machine->keepalive_count_inc();
975  if (state_machine->get_keepalive_count() == 3) {
976  state_machine->connect_attempts_clear();
977  }
978  state_machine->StartHoldTimer();
979  return discard_event();
980  }
981 
982  sc::result react(const EvXmppMessageStanza &event) {
983  XmppStateMachine *state_machine = &context<XmppStateMachine>();
984  if (event.session != state_machine->session()) {
985  return discard_event();
986  }
987  state_machine->StartHoldTimer();
988  state_machine->connection()->ProcessXmppChatMessage(
989  static_cast<const XmppStanza::XmppChatMessage *>(event.msg.get()));
990  return discard_event();
991  }
992 
993  sc::result react(const EvXmppIqStanza &event) {
994  XmppStateMachine *state_machine = &context<XmppStateMachine>();
995  if (event.session != state_machine->session()) {
996  return discard_event();
997  }
998  state_machine->StartHoldTimer();
999  state_machine->connection()->ProcessXmppIqMessage(
1000  static_cast<const XmppStanza::XmppMessage *>(event.msg.get()));
1001  return discard_event();
1002  }
1003 
1004  sc::result react(const EvHoldTimerExpired &event) {
1005  XmppStateMachine *state_machine = &context<XmppStateMachine>();
1006  if (state_machine->HoldTimerCancelled()) {
1007  SM_LOG(state_machine,
1008  "Discard EvHoldTimerExpired in (Established) State");
1009  return discard_event();
1010  }
1011  XMPP_NOTICE(XmppStateMachineNotice,
1012  state_machine->connection()->ToUVEKey(),
1014  state_machine->ChannelType(),
1015  "EvHoldTimerExpired in (Established) State. Transit to IDLE");
1016  state_machine->SendConnectionInfo(event.Name());
1017  state_machine->AssertOnHoldTimeout();
1018  state_machine->ResetSession();
1019  if (state_machine->IsActiveChannel()) {
1020  return transit<Active>();
1021  } else {
1022  return transit<Idle>();
1023  }
1024  }
1025 
1026  sc::result react(const EvStop &event) {
1027  XmppStateMachine *state_machine = &context<XmppStateMachine>();
1028  state_machine->SendConnectionInfo(event.Name());
1029  state_machine->ResetSession();
1030  if (state_machine->IsActiveChannel()) {
1031  return transit<Active>();
1032  } else {
1033  return transit<Idle>();
1034  }
1035  }
1036 
1037  sc::result react(const EvAdminDown &event) {
1038  XmppStateMachine *state_machine = &context<XmppStateMachine>();
1039  state_machine->ResetSession();
1040  XmppConnectionInfo info;
1041  info.set_close_reason("Administratively down");
1042  state_machine->connection()->set_close_reason("Administratively down");
1043  state_machine->SendConnectionInfo(&info, event.Name(), "Idle");
1044  return transit<Idle>();
1045  }
1046 };
1047 
1048 } // namespace xmsm
1049 
1051  static bool init_ = false;
1052  static bool assert_ = false;
1053 
1054  if (!init_) {
1055  char *str = getenv("XMPP_ASSERT_ON_HOLD_TIMEOUT");
1056  if (str && strtoul(str, NULL, 0) != 0) assert_ = true;
1057  init_ = true;
1058  }
1059 
1060  if (!assert_) return;
1061 
1062  if (connection()) {
1063  connection()->LogMsg("HOLD TIMER EXPIRED: ");
1064  } else {
1065  LOG4CPLUS_DEBUG(log4cplus::Logger::getRoot(), "HOLD TIMER EXPIRED: ");
1066  }
1067 
1068  assert(!assert_);
1069 }
1070 
1072  XmppConnection *connection = this->connection();
1073  set_session(NULL);
1074  CancelHoldTimer();
1075 
1076  if (!connection)
1077  return;
1078 
1079  // Stop keepalives, transition to IDLE and notify registered entities.
1080  connection->StopKeepAliveTimer();
1081  connection->ChannelMux()->HandleStateEvent(xmsm::IDLE);
1082  if (IsActiveChannel())
1083  return;
1084 
1085  // Retain the connection if graceful restart is supported.
1086  XmppServer *server = dynamic_cast<XmppServer *>(connection->server());
1087  if (!server->IsPeerCloseGraceful())
1088  connection->ManagedDelete();
1089 }
1090 
1092  bool auth_enabled, int config_hold_time)
1093  : work_queue_(TaskScheduler::GetInstance()->GetTaskId("xmpp::StateMachine"),
1094  connection->GetTaskInstance(),
1095  boost::bind(&XmppStateMachine::DequeueEvent, this, _1)),
1096  connection_(connection),
1097  session_(NULL),
1098  server_(connection->server()),
1099  connect_timer_(
1100  TimerManager::CreateTimer(*server_->event_manager()->io_service(),
1101  "Connect timer",
1102  TaskScheduler::GetInstance()->GetTaskId("xmpp::StateMachine"),
1103  connection->GetTaskInstance())),
1104  open_timer_(
1105  TimerManager::CreateTimer(*server_->event_manager()->io_service(),
1106  "Open timer",
1107  TaskScheduler::GetInstance()->GetTaskId("xmpp::StateMachine"),
1108  connection->GetTaskInstance())),
1109  hold_timer_(
1110  TimerManager::CreateTimer(*server_->event_manager()->io_service(),
1111  "Hold timer",
1112  TaskScheduler::GetInstance()->GetTaskId("xmpp::StateMachine"),
1113  connection->GetTaskInstance())),
1114  config_hold_time_(config_hold_time),
1115  hold_time_(GetConfiguredHoldTime()),
1116  attempts_(0),
1117  keepalive_count_(0),
1118  deleted_(false),
1119  in_dequeue_(false),
1120  is_active_(active),
1121  auth_enabled_(auth_enabled),
1122  state_(xmsm::IDLE),
1123  last_state_(xmsm::IDLE),
1124  openconfirm_state_(xmsm::OPENCONFIRM_INIT) {
1125  handshake_cb_ = boost::bind(
1127 }
1128 
1130  assert(!deleted_);
1131  deleted_ = true;
1133  set_session(NULL);
1134 
1135  // Explicitly call the state destructor before the state machine itself.
1136  // This is needed because some of the destructors access the state machine
1137  // context.
1138  terminate();
1139 
1140  // Delete timer after state machine is terminated so that there is no
1141  // possible reference to the timers being deleted any more
1145 }
1146 
1148  initiate();
1150 }
1151 
1152 // Note this api does not enqueue the deletion of TCP session
1154  if (session_ != NULL) {
1155  session_->set_observer(NULL);
1157  session_->Close();
1159  session_ = NULL;
1160  }
1161 }
1162 
1164  // If there is a session assigned to this state machine, reset the observer
1165  // so that tcp does not have a reference to 'this' which is going away
1166  if (session != NULL) {
1167  session->set_observer(NULL);
1169  session->Close();
1171  }
1172 }
1173 
1175  if (session_ != NULL) {
1178  }
1179  session_ = static_cast<XmppSession *>(session);
1180 }
1181 
1182 void XmppStateMachine::TimerErrorHandler(std::string name, std::string error) {
1183 }
1184 
1187 
1188  // Add up to +/- kJitter percentage to reduce connection collisions.
1189  int ms = ((seconds)? seconds * 1000 : 50);
1190  ms = (ms * (100 - kJitter)) / 100;
1191  ms += (ms * (rand() % (kJitter * 2))) / 100;
1192  connect_timer_->Start(ms,
1193  boost::bind(&XmppStateMachine::ConnectTimerExpired, this),
1194  boost::bind(&XmppStateMachine::TimerErrorHandler, this, _1, _2));
1195 }
1196 
1199 }
1200 
1202  CancelOpenTimer();
1203  open_timer_->Start(seconds * 1000,
1204  boost::bind(&XmppStateMachine::OpenTimerExpired, this),
1205  boost::bind(&XmppStateMachine::TimerErrorHandler, this, _1, _2));
1206 }
1207 
1209  open_timer_->Cancel();
1210 }
1211 
1213  static std::atomic<bool> env_checked = std::atomic<bool>();
1214  static std::atomic<int> env_hold_time = std::atomic<int>();
1215 
1216  // For testing only - configure through environment variable.
1217  if (!env_checked) {
1218  char *keepalive_time_str = getenv("XMPP_KEEPALIVE_SECONDS");
1219  if (keepalive_time_str) {
1220  env_hold_time = strtoul(keepalive_time_str, NULL, 0) * 3;
1221  env_checked = true;
1222  return env_hold_time;
1223  } else {
1224  env_checked = true;
1225  }
1226  } else if (env_hold_time) {
1227  return env_hold_time;
1228  } else if (config_hold_time_) {
1229  return config_hold_time_;
1230  }
1231 
1232  // Use hard coded default.
1233  return kHoldTime;
1234 }
1235 
1237  CancelHoldTimer();
1238 
1239  if (hold_time_ <= 0)
1240  return;
1241 
1242  hold_timer_->Start(hold_time_ * 1000,
1243  boost::bind(&XmppStateMachine::HoldTimerExpired, this),
1244  boost::bind(&XmppStateMachine::TimerErrorHandler, this, _1, _2));
1245 }
1246 
1248  hold_timer_->Cancel();
1249 }
1250 
1252 }
1253 
1255  XMPP_UTDEBUG(XmppStateMachineTimerExpire,
1256  connection() ? connection()->ToUVEKey() : "",
1257  XMPP_PEER_DIR_NA, this->ChannelType(), "Connect", StateName());
1259  return false;
1260 }
1261 
1263  XMPP_NOTICE(XmppEventLog, connection()->ToUVEKey(), XMPP_PEER_DIR_NA,
1264  this->ChannelType(),
1265  "Event: OpenTimer Expired ",
1266  connection()->endpoint().address().to_string(),
1267  connection()->GetTo());
1269  return false;
1270 }
1271 
1272 
1274  boost::system::error_code error;
1275 
1276  // Reset hold timer if there is data already present in the socket.
1277  if (session() && session()->socket() &&
1278  session()->socket()->available(error) > 0) {
1279  return true;
1280  }
1281  XMPP_NOTICE(XmppEventLog, connection()->ToUVEKey(), XMPP_PEER_DIR_NA,
1282  this->ChannelType(), "Event: HoldTimer Expired ",
1283  connection()->endpoint().address().to_string(),
1284  connection()->GetTo());
1286  return false;
1287 }
1288 
1290  TcpSession *session, TcpSession::Event event) {
1291  switch (event) {
1292  case TcpSession::ACCEPT:
1293  break;
1295  XMPP_NOTICE(XmppEventLog, session->ToUVEKey(), XMPP_PEER_DIR_IN,
1296  this->ChannelType(), "Event: Tcp Connected ",
1297  connection()->endpoint().address().to_string(),
1298  connection()->GetTo());
1299  Enqueue(xmsm::EvTcpConnected(static_cast<XmppSession *>(session)));
1300  break;
1302  XMPP_NOTICE(XmppEventLog, session->ToUVEKey(), XMPP_PEER_DIR_IN,
1303  this->ChannelType(), "Event: Tcp Connect Fail ",
1304  connection()->endpoint().address().to_string(),
1305  connection()->GetTo());
1308  break;
1309  case TcpSession::CLOSE:
1310  XMPP_NOTICE(XmppEventLog, session->ToUVEKey(), XMPP_PEER_DIR_IN,
1311  this->ChannelType(), "Event: Tcp Connection Closed ",
1312  connection()->endpoint().address().to_string(),
1313  connection()->GetTo());
1314  Enqueue(xmsm::EvTcpClose(static_cast<XmppSession *>(session)));
1316  break;
1317  default:
1318  XMPP_WARNING(XmppUnknownEvent, session->ToUVEKey(), XMPP_PEER_DIR_IN,
1319  this->ChannelType(), event);
1320  break;
1321  }
1322 }
1323 
1325  string state = "PassiveOpen in state: " + StateName();
1326  XMPP_NOTICE(XmppEventLog, session->ToUVEKey(), XMPP_PEER_DIR_IN,
1327  this->ChannelType(), state,
1328  session->Connection()->endpoint().address().to_string(), "");
1330 }
1331 
1332 // Process XmppStream header message received over a session. Close the stream
1333 // if an old session is still present and undergoing graceful restart.
1334 //
1335 // Return true if msg is enqueued for further processing, false otherwise.
1337  const XmppStanza::XmppMessage *msg) {
1338  XmppConnectionManager *connection_manager =
1339  dynamic_cast<XmppConnectionManager *>(connection_->server());
1340  std::scoped_lock lock(connection_manager->mutex());
1341 
1342  // Update "To" information which can be used to map an older session
1343  session->Connection()->SetTo(msg->from);
1344 
1345  XmppServer *xmpp_server = dynamic_cast<XmppServer *>(server_);
1346  XmppConnectionEndpoint *endpoint = NULL;
1347 
1348  // Look for an endpoint which may already exist
1349  if (xmpp_server) {
1350  endpoint =
1351  xmpp_server->FindConnectionEndpoint(connection_->ToString());
1352 
1353  if (!xmpp_server->subcluster_name().empty() &&
1354  xmpp_server->subcluster_name() != msg->xmlns) {
1355  string reason = "Subcluster mismatch: Agent subcluster " +
1356  msg->xmlns + ", Control subcluster " +
1357  xmpp_server->subcluster_name();
1358  XMPP_WARNING(XmppDeleteConnection, session->ToUVEKey(),
1360  "Drop new xmpp connection " + session->ToString() +
1361  " as " + reason);
1362  session->Connection()->set_close_reason(reason);
1364  delete msg;
1365  return;
1366  }
1367  }
1368 
1369  // If there is no connection already associated with the end-point,
1370  // process the incoming open message and move forward with the session
1371  // establishment.
1372  if (!endpoint || !endpoint->connection() ||
1373  connection_ == endpoint->connection()) {
1375  return;
1376  }
1377 
1378  // Check if the IP addresses match.
1379  boost::asio::ip::address addr =
1380  endpoint->connection()->endpoint().address();
1381  if (connection_->endpoint().address() != addr) {
1382  XMPP_WARNING(XmppDeleteConnection, session->ToUVEKey(),
1384  "Drop new xmpp connection " + session->ToString() +
1385  " as another connection with same name " + msg->from +
1386  " but with different IP address " + addr.to_string() +
1387  " already exists");
1389  delete msg;
1390  return;
1391  }
1392 
1393  XmppChannelMux *channel = endpoint->connection()->ChannelMux();
1394 
1395  // If GR Helper mode is not enabled, ignore the new connection request.
1396  // Existing connection, if down will get cleaned up eventually. If it is
1397  // up, it shall remain intact.
1398  if (!xmpp_server->IsPeerCloseGraceful()) {
1399  XMPP_NOTICE(XmppDeleteConnection, session->ToUVEKey(),
1401  "Drop new xmpp connection " + session->ToString() +
1402  " as another connection is alreready present");
1404  delete msg;
1405  return;
1406  }
1407 
1408  XmppStateMachine *old_sm = endpoint->connection()->state_machine();
1409 
1410  // Bring down old session if connection is already up and ready. This is
1411  // the scenario in which old session's TCP did not learn the session down
1412  // event, possibly due to compute cold reboot. In that case, trigger
1413  // closure (and possibly GR) process for the old session.
1414  if (channel->GetPeerState() == xmps::READY) {
1415  XMPP_NOTICE(XmppDeleteConnection, old_sm->session()->ToUVEKey(),
1416  XMPP_PEER_DIR_IN, "Delete old xmpp connection " +
1417  old_sm->session()->ToString() +
1418  " as a new connection as been initiated (GR Helper is active)");
1419  old_sm->Enqueue(xmsm::EvTcpClose(old_sm->session()));
1420 
1421  // Drop the new session until old one is deleted or marked stale.
1423  delete msg;
1424  return;
1425  }
1426 
1427  // If previous closure is still in progress, drop the new connection.
1428  if (channel->ReceiverCount()) {
1429  XMPP_NOTICE(XmppDeleteConnection, session->ToUVEKey(),
1431  "Drop new xmpp connection " + session->ToString() +
1432  " as current connection is still under deletion");
1434  delete msg;
1435  return;
1436  }
1437 
1438  // Now we reach for the classic GR case, in which existing session stale
1439  // process is complete, (peer is in GR/LLGR timer wait state).
1440  // In this case, we should process the open message, and later switch to
1441  // the new connection and state machine, retaining the old XmppPeer,
1442  // BgpXmppChannel, routes, etc.
1444 }
1445 
1447  const XmppStanza::XmppMessage *msg) {
1448  if (!Enqueue(xmsm::EvXmppMessage(session, msg)))
1449  delete msg;
1450 }
1451 
1453  const XmppStanza::XmppMessage *msg) {
1454  // Bail if session is already reset and disassociated from the connection.
1455  if (!session->Connection()) {
1456  delete msg;
1457  return;
1458  }
1459 
1460  const XmppStanza::XmppStreamMessage *stream_msg =
1461  static_cast<const XmppStanza::XmppStreamMessage *>(msg);
1462 
1463  switch (msg->type) {
1465  if (stream_msg->strmtype ==
1467 
1468  switch (stream_msg->strmtlstype) {
1471  msg));
1472  break;
1475  break;
1478  break;
1479  default:
1480  break;
1481  }
1482 
1483  } else if (stream_msg->strmtype ==
1485  stream_msg->strmtype ==
1488  break;
1491  break;
1492  case XmppStanza::IQ_STANZA:
1494  break;
1497  break;
1498  default:
1499  if (!msg->IsValidType(msg->type)) {
1500  XMPP_NOTICE(XmppStateMachineUnsupportedMessage,
1502  ChannelType(), (int)msg->type);
1503  }
1504  delete msg;
1505  break;
1506  }
1507 
1508 }
1509 
1511  Enqueue(xmsm::EvStop());
1512 }
1513 
1515  assert(IsActiveChannel());
1516  if (down) {
1518  } else {
1520  }
1521 }
1522 
1525  XmppSession *sess = static_cast<XmppSession *>(session);
1526  switch(resp) {
1529  break;
1532  break;
1533  default:
1534  break;
1535  }
1536 }
1537 
1539  last_state_ = state_;
1540  state_ = state;
1542 
1543  if (!logUVE()) return;
1544 
1545  XmppPeerInfoData peer_info;
1546  peer_info.set_name(connection()->ToUVEKey());
1547  PeerStateInfo state_info;
1548  state_info.set_state(StateName());
1549  state_info.set_last_state(LastStateName());
1550  state_info.set_last_state_at(state_since_);
1551  peer_info.set_state_info(state_info);
1552  assert(!peer_info.get_name().empty());
1553  XMPPPeerInfo::Send(peer_info);
1554 }
1555 
1556 
1558  openconfirm_state_ = state;
1559 }
1560 
1561 static const char *state_names[] = {
1562  "Idle",
1563  "Active",
1564  "Connect",
1565  "OpenSent",
1566  "OpenConfirm",
1567  "Established" };
1568 
1570  return state_names[state_];
1571 }
1572 
1574  return state_names[last_state_];
1575 }
1576 
1579 }
1580 
1582  return state_;
1583 }
1584 
1586  return openconfirm_state_;
1587 }
1588 
1590  connection_->set_session(static_cast<XmppSession *>(session_));
1591 }
1592 
1594 
1596  int backoff = attempts_ > 6 ? 6 : attempts_;
1597  return std::min(backoff ? 1 << (backoff - 1) : 0, kConnectInterval);
1598 }
1599 
1601  return is_active_;
1602 }
1603 
1605  return connection()->logUVE();
1606 }
1607 
1609  return (IsActiveChannel() ? " Mode Client: " : " Mode Server: " );
1610 }
1611 
1613  boost::intrusive_ptr<const sc::event_base> event) {
1614  // Process message event and enqueue additional events as necessary.
1615  const xmsm::EvXmppMessage *ev_xmpp_message =
1616  dynamic_cast<const xmsm::EvXmppMessage *>(event.get());
1617  if (ev_xmpp_message) {
1618  ProcessMessage(ev_xmpp_message->session, ev_xmpp_message->msg);
1619  } else {
1620  ProcessEvent(*event);
1621  event.reset();
1622  }
1623  return true;
1624 }
1625 
1626 void XmppStateMachine::ProcessEvent(const sc::event_base &event) {
1627  const xmsm::EvTcpDeleteSession *deferred_delete =
1628  dynamic_cast<const xmsm::EvTcpDeleteSession *>(&event);
1629  XMPP_UTDEBUG(XmppStateMachineDequeueEvent,
1630  connection() ? connection()->ToUVEKey() : "",
1632  connection() ?
1633  connection()->endpoint().address().to_string() : "",
1634  connection() ? connection()->GetTo() : "");
1635  if (deferred_delete) {
1636  TcpSession *session = deferred_delete->session;
1638  return;
1639  }
1640  if (deleted_) {
1641  return;
1642  }
1643 
1644  update_last_event(TYPE_NAME(event));
1645  in_dequeue_ = true;
1646  process_event(event);
1647  in_dequeue_ = false;
1648 }
1649 
1650 void XmppStateMachine::unconsumed_event(const sc::event_base &event) {
1651  XMPP_INFO(XmppUnconsumedEvent, connection() ? connection()->ToUVEKey() : "",
1653 }
1654 
1655 void XmppStateMachine::update_last_event(const std::string &event) {
1656  set_last_event(event);
1657 
1658  if (!logUVE()) return;
1659 
1660  // Skip iq and message events.
1661  if (event == "xmsm::EvXmppIqStanza" ||
1662  event == "xmsm::EvXmppMessageStanza") {
1663  return;
1664  }
1665 
1666  // Skip keepalive events after we've reached established state.
1667  if (state_ == xmsm::ESTABLISHED && event == "xmsm::EvXmppKeepalive") {
1668  return;
1669  }
1670 
1671  XmppPeerInfoData peer_info;
1672  peer_info.set_name(connection()->ToUVEKey());
1673  PeerEventInfo event_info;
1674  event_info.set_last_event(last_event_);
1675  event_info.set_last_event_at(last_event_at_);
1676  peer_info.set_event_info(event_info);
1677 
1678  assert(!peer_info.get_name().empty());
1679  XMPPPeerInfo::Send(peer_info);
1680 }
1681 
1682 //
1683 // Enqueue an event to xmpp state machine.
1684 // Return false if the event is not enqueued.
1685 //
1686 bool XmppStateMachine::Enqueue(const sc::event_base &event) {
1687  if (!deleted_) {
1688  work_queue_.Enqueue(event.intrusive_from_this());
1689  return true;
1690  }
1691 
1692  return false;
1693 }
1694 
1695 // Object trace routines.
1696 void XmppStateMachine::SendConnectionInfo(const string &event,
1697  const string &nextstate) {
1698  XmppConnectionInfo info;
1699  SendConnectionInfo(&info, event, nextstate);
1700  return;
1701 }
1702 
1703 void XmppStateMachine::SendConnectionInfo(XmppConnectionInfo *info,
1704  const string &event, const string &nextstate) {
1705 
1706  info->set_ip_address(this->connection()->endpoint().address().to_string());
1707  info->set_state(StateName());
1708  info->set_event(event);
1709  if (!nextstate.empty()) {
1710  info->set_next_state(nextstate);
1711  }
1712  XMPP_CONNECTION_LOG_MSG(*info);
1713  return;
1714 }
1715 
1716 // Resurrect an old xmpp connection if present (when under GracefulRestart)
1717 //
1718 // During Graceful Restart (or otherwise), new connections are rejected in
1719 // ProcessStreamHeaderMessage() itself until old one's cleanup process is
1720 // complete and the system is ready to start a new session.
1721 //
1722 // Hence in here, when called upon receipt of OpenMessage, we can try to reuse
1723 // old XmppConnection if present and there by complete any pending GR process
1724 //
1725 // We do so by reusing XmppConnection, XmppChannel, etc. from the old connection
1726 // and only use the XmppSession and XmppStateMachine from the new session
1727 //
1728 // New connection is instead associated with the old state machine and session,
1729 // and their deletion is triggered
1731  XmppSession *new_session) {
1732 
1733  // Look for an endpoint (which is a persistent data structure) across
1734  // xmpp session flips
1735  bool created;
1736  XmppConnectionEndpoint *connection_endpoint =
1737  static_cast<XmppServer *>(
1738  new_connection->server())->LocateConnectionEndpoint(
1739  static_cast<XmppServerConnection *>(new_connection), created);
1740 
1741  // If this is a new endpoint, then there is no older connection to manage.
1742  if (created)
1743  return;
1744 
1745  // GR Helper must be enabled when we are trying to resurrect connection.
1746  XmppServer *server = dynamic_cast<XmppServer *>(new_connection->server());
1747  assert(server->IsPeerCloseGraceful());
1748 
1749  XMPP_NOTICE(XmppCreateConnection, new_session->ToUVEKey(),
1751  "Resurrect xmpp connection " + new_session->ToString());
1752 
1753  // Retrieve old XmppConnection and XmppStateMachine (to reuse)
1754  XmppConnection *old_xmpp_connection = connection_endpoint->connection();
1755  assert(old_xmpp_connection);
1756 
1757  XmppStateMachine *old_state_machine = old_xmpp_connection->state_machine();
1758  assert(old_state_machine);
1759 
1760  // Swap Old and New connections and state machines linkages
1761  new_connection->SwapXmppStateMachine(old_xmpp_connection);
1762  this->SwapXmppConnection(old_state_machine);
1763 
1764  // Update XmppConnection in the old session.
1765  XmppSession *old_xmpp_session = old_state_machine->session();
1766  if (old_xmpp_session)
1767  old_xmpp_session->SetConnection(new_connection);
1768  new_session->SetConnection(old_xmpp_connection);
1769 
1770  // Set new session with the old connection as it would be the current active
1771  // connection from now on.
1772  old_xmpp_connection->set_session(new_session);
1773 
1774  // Trigger deletion of the new connection which now is associated wth the
1775  // the old_state_machine
1776  new_connection->Shutdown();
1777 }
1778 
1780  swap(connection_, other->connection_);
1782 }
virtual Socket * socket() const
Definition: ssl_session.cc:99
void TriggerSslHandShake(SslHandShakeCallbackHandler)
Definition: ssl_session.cc:201
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
virtual void Connect(TcpSession *session, Endpoint remote)
Definition: tcp_server.cc:477
virtual void DeleteSession(TcpSession *session)
Definition: tcp_server.cc:200
@ CONNECT_COMPLETE
Definition: tcp_session.h:47
@ CONNECT_FAILED
Definition: tcp_session.h:48
TcpServer * server()
Definition: tcp_session.h:85
const std::string & ToUVEKey() const
Definition: tcp_session.h:175
int32_t remote_port() const
Definition: tcp_session.cc:549
virtual std::string ToString() const
Definition: tcp_session.h:80
void set_observer(EventObserver observer)
Definition: tcp_session.cc:220
virtual void AsyncReadStart()
Definition: tcp_session.cc:176
int32_t local_port() const
Definition: tcp_session.cc:537
void Close()
Definition: tcp_session.cc:356
static bool DeleteTimer(Timer *Timer)
Definition: timer.cc:222
bool Cancel()
Definition: timer.cc:150
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
Definition: timer.cc:108
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:249
void Shutdown(bool delete_entries=true)
Definition: queue_task.h:153
void HandleStateEvent(xmsm::XmState state)
virtual xmps::PeerState GetPeerState() const
size_t ReceiverCount() const
XmppConnection * connection()
std::mutex & mutex() const
virtual void increment_flap_count()=0
bool IsActiveChannel() const
XmppChannelMux * ChannelMux()
virtual bool SendStreamFeatureRequest(XmppSession *session)
int ProcessXmppIqMessage(const XmppStanza::XmppMessage *)
XmppSession * CreateSession()
std::string & GetTo()
bool IsDeleted() const
void SwapContents(XmppConnection *other)
virtual boost::asio::ip::tcp::endpoint local_endpoint() const
virtual bool SendOpen(XmppSession *session)
virtual void ManagedDelete()=0
virtual bool SendStartTls(XmppSession *session)
virtual boost::asio::ip::tcp::endpoint endpoint() const
TcpServer * server()
virtual bool SendProceedTls(XmppSession *session)
int ProcessXmppChatMessage(const XmppStanza::XmppChatMessage *)
bool logUVE() const
void SetTo(const std::string &)
void SwapXmppStateMachine(XmppConnection *other)
void StartKeepAliveTimer()
void SendClose(XmppSession *session)
XmppStateMachine * state_machine()
virtual bool SendOpenConfirm(XmppSession *session)
void ProcessSslHandShakeResponse(SslSessionPtr session, const boost::system::error_code &error)
const std::string & ToString() const
void set_session(XmppSession *session)
const std::string & ToUVEKey() const
virtual void set_close_reason(const std::string &reason)=0
virtual bool IsPeerCloseGraceful() const
Definition: xmpp_server.cc:281
XmppConnectionEndpoint * FindConnectionEndpoint(const std::string &endpoint_name)
Definition: xmpp_server.cc:676
const std::string subcluster_name() const
Definition: xmpp_server.h:106
XmppConnection * Connection()
Definition: xmpp_session.h:27
void SetConnection(XmppConnection *connection)
Definition: xmpp_session.cc:53
void ClearConnection()
Definition: xmpp_session.cc:64
XmppMessageType type
Definition: xmpp_proto.h:58
bool IsValidType(XmppMessageType type) const
Definition: xmpp_proto.h:65
@ WHITESPACE_MESSAGE_STANZA
Definition: xmpp_proto.h:21
@ MESSAGE_STANZA
Definition: xmpp_proto.h:19
@ STREAM_HEADER
Definition: xmpp_proto.h:18
void update_last_event(const std::string &event)
xmsm::XmOpenConfirmState OpenConfirmStateType() const
void set_state(xmsm::XmState state)
void ProcessEvent(const sc::event_base &event)
xmsm::XmState get_state()
virtual void StartHoldTimer()
void SetAdminState(bool down)
XmppSession * session_
XmppStateMachine(XmppConnection *connection, bool active, bool auth_enabled=false, int config_hold_time=kHoldTime)
void DeleteSession(XmppSession *session)
std::string StateName() const
virtual void StartOpenTimer(int seconds)
static const int kConnectInterval
bool DequeueEvent(boost::intrusive_ptr< const sc::event_base > event)
void OnStart(const xmsm::EvStart &event)
SslHandShakeCallbackHandler HandShakeCbHandler()
void ProcessStreamHeaderMessage(XmppSession *session, const XmppStanza::XmppMessage *msg)
xmsm::XmState StateType() const
XmppConnection * connection()
const char * ChannelType()
WorkQueue< boost::intrusive_ptr< const sc::event_base > > work_queue_
void set_last_event(const std::string &event)
void TimerErrorHandler(std::string name, std::string error)
std::string LastStateName() const
bool PassiveOpen(XmppSession *session)
virtual void StartConnectTimer(int seconds)
void SwapXmppConnection(XmppStateMachine *other)
XmppConnection * connection_
std::string LastStateChangeAt() const
void ProcessMessage(XmppSession *session, const XmppStanza::XmppMessage *msg)
xmsm::XmOpenConfirmState openconfirm_state_
void OnEvent(SslSession *session, xmsm::SslHandShakeResponse)
bool Enqueue(const sc::event_base &ev)
void OnMessage(XmppSession *session, const XmppStanza::XmppMessage *msg)
void set_session(TcpSession *session)
int get_keepalive_count() const
xmsm::XmState state_
XmppSession * session()
void set_openconfirm_state(xmsm::XmOpenConfirmState state)
int GetConfiguredHoldTime() const
void SendConnectionInfo(const std::string &event, const std::string &nextstate="")
int get_connect_attempts() const
xmsm::XmState last_state_
static const int kMaxAttempts
void ResurrectOldConnection(XmppConnection *connection, XmppSession *session)
static const int kHoldTime
static const int kOpenTime
static const int kJitter
virtual void OnSessionEvent(TcpSession *session, TcpSession::Event event)
void unconsumed_event(const sc::event_base &event)
SslHandShakeCallbackHandler handshake_cb_
#define TYPE_NAME(_type)
Definition: logging.h:33
#define LOG(_Level, _Msg)
Definition: logging.h:35
@ READY
Definition: xmpp_channel.h:18
@ EvTLSHANDSHAKE_SUCCESS
@ EvTLSHANDSHAKE_FAILURE
@ OPENCONFIRM_FEATURE_NEGOTIATION
@ OPENCONFIRM_FEATURE_SUCCESS
@ OPENCONFIRM_INIT
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:20
XmppStreamTlsType strmtlstype
Definition: xmpp_proto.h:100
XmppStreamMsgType strmtype
Definition: xmpp_proto.h:99
Active(my_context ctx)
sc::result react(const EvXmppOpen &event)
mpl::list< sc::custom_reaction< EvAdminDown >, sc::custom_reaction< EvConnectTimerExpired >, sc::custom_reaction< EvOpenTimerExpired >, sc::custom_reaction< EvTcpPassiveOpen >, sc::custom_reaction< EvTcpClose >, sc::custom_reaction< EvXmppOpen >, sc::custom_reaction< EvStop > > reactions
sc::result react(const EvConnectTimerExpired &event)
sc::result react(const EvAdminDown &event)
sc::result react(const EvStop &event)
sc::result react(const EvTcpPassiveOpen &event)
sc::result react(const EvOpenTimerExpired &event)
sc::result react(const EvTcpClose &event)
void StartSession(XmppStateMachine *state_machine)
void CloseSession(XmppStateMachine *state_machine)
sc::result react(const EvAdminDown &event)
sc::result react(const EvTcpConnectFail &event)
mpl::list< sc::custom_reaction< EvAdminDown >, sc::custom_reaction< EvConnectTimerExpired >, sc::custom_reaction< EvTcpConnected >, sc::custom_reaction< EvTcpConnectFail >, sc::custom_reaction< EvTcpClose >, sc::custom_reaction< EvStop > > reactions
sc::result react(const EvTcpClose &event)
sc::result react(const EvStop &event)
sc::result react(const EvTcpConnected &event)
Connect(my_context ctx)
sc::result react(const EvConnectTimerExpired &event)
static const char * Name()
static const char * Name()
static const char * Name()
static const char * Name()
static const char * Name()
boost::shared_ptr< const XmppStanza::XmppMessage > msg
EvStartTls(XmppSession *session, const XmppStanza::XmppMessage *msg)
static const char * Name()
static const char * Name()
boost::shared_ptr< const XmppStanza::XmppMessage > msg
EvStreamFeatureRequest(XmppSession *session, const XmppStanza::XmppMessage *msg)
static const char * Name()
EvTcpClose(XmppSession *session)
EvTcpConnectFail(XmppSession *session)
static const char * Name()
static const char * Name()
EvTcpConnected(XmppSession *session)
EvTcpDeleteSession(TcpSession *session)
static const char * Name()
EvTcpPassiveOpen(XmppSession *session)
static const char * Name()
EvTlsHandShakeFailure(XmppSession *session)
EvTlsHandShakeSuccess(XmppSession *session)
EvTlsProceed(XmppSession *session, const XmppStanza::XmppMessage *msg)
boost::shared_ptr< const XmppStanza::XmppMessage > msg
static const char * Name()
EvXmppIqStanza(XmppSession *session, const XmppStanza::XmppMessage *msg)
static const char * Name()
boost::shared_ptr< const XmppStanza::XmppMessage > msg
static const char * Name()
EvXmppKeepalive(XmppSession *session, const XmppStanza::XmppMessage *msg)
boost::shared_ptr< const XmppStanza::XmppMessage > msg
boost::shared_ptr< const XmppStanza::XmppMessage > msg
static const char * Name()
EvXmppMessageStanza(XmppSession *session, const XmppStanza::XmppMessage *msg)
static const char * Name()
EvXmppMessage(XmppSession *session, const XmppStanza::XmppMessage *msg)
const XmppStanza::XmppMessage * msg
static const char * Name()
EvXmppOpenReceive(XmppSession *session)
boost::shared_ptr< const XmppStanza::XmppStreamMessage > msg
EvXmppOpen(XmppSession *session, const XmppStanza::XmppMessage *msg)
static const char * Name()
sc::transition< EvStart, Active, XmppStateMachine, &XmppStateMachine::OnStart > reactions
Idle(my_context ctx)
sc::result react(const EvStartTls &event)
sc::result react(const EvStop &event)
sc::result react(const EvHoldTimerExpired &event)
mpl::list< sc::custom_reaction< EvAdminDown >, sc::custom_reaction< EvTcpClose >, sc::custom_reaction< EvHoldTimerExpired >, sc::custom_reaction< EvStreamFeatureRequest >, sc::custom_reaction< EvStartTls >, sc::custom_reaction< EvTlsProceed >, sc::custom_reaction< EvTlsHandShakeSuccess >, sc::custom_reaction< EvTlsHandShakeFailure >, sc::custom_reaction< EvXmppOpen >, sc::custom_reaction< EvStop > > reactions
sc::result react(const EvTlsHandShakeSuccess &event)
OpenConfirm(my_context ctx)
void CloseSession(XmppStateMachine *state_machine)
sc::result react(const EvTcpClose &event)
sc::result react(const EvTlsHandShakeFailure &event)
sc::result react(const EvTlsProceed &event)
sc::result react(const EvAdminDown &event)
sc::result react(const EvXmppOpen &event)
sc::result react(const EvStreamFeatureRequest &event)
sc::result react(const EvAdminDown &event)
sc::result react(const EvStop &event)
mpl::list< sc::custom_reaction< EvAdminDown >, sc::custom_reaction< EvTcpClose >, sc::custom_reaction< EvXmppOpen >, sc::custom_reaction< EvHoldTimerExpired >, sc::custom_reaction< EvStop > > reactions
OpenSent(my_context ctx)
sc::result react(const EvTcpClose &event)
sc::result react(const EvXmppOpen &event)
void CloseSession(XmppStateMachine *state_machine)
sc::result react(const EvHoldTimerExpired &event)
sc::result react(const EvXmppMessageStanza &event)
sc::result react(const EvTcpClose &event)
sc::result react(const EvXmppIqStanza &event)
sc::result react(const EvStop &event)
sc::result react(const EvHoldTimerExpired &event)
sc::result react(const EvAdminDown &event)
sc::result react(const EvXmppKeepalive &event)
mpl::list< sc::custom_reaction< EvAdminDown >, sc::custom_reaction< EvTcpClose >, sc::custom_reaction< EvXmppKeepalive >, sc::custom_reaction< EvXmppMessageStanza >, sc::custom_reaction< EvXmppIqStanza >, sc::custom_reaction< EvHoldTimerExpired >, sc::custom_reaction< EvStop > > reactions
static boost::posix_time::ptime UTCUsecToPTime(uint64_t tusec)
Definition: time_util.h:39
static uint64_t UTCTimestampUsec()
Definition: time_util.h:14
#define XMPP_PEER_DIR_NA
Definition: xmpp_log.h:17
#define XMPP_UTDEBUG(obj,...)
Definition: xmpp_log.h:68
#define XMPP_WARNING(obj,...)
Definition: xmpp_log.h:36
#define XMPP_INFO(obj,...)
Definition: xmpp_log.h:52
#define XMPP_CONNECTION_LOG_MSG(info)
Definition: xmpp_log.h:84
#define XMPP_NOTICE(obj,...)
Definition: xmpp_log.h:44
#define XMPP_PEER_DIR_IN
Definition: xmpp_log.h:16
#define SM_LOG(_sm, _msg)
static const char * state_names[]