@@ -59,7 +59,7 @@ struct Client;
5959struct Odid
6060{
6161 Odid () {} // Default constructor needed because of std::map
62-
62+
6363 Odid (Session &session, uint32_t odid)
6464 : session(&session)
6565 , odid(odid)
@@ -73,7 +73,7 @@ struct Odid
7373 std::time_t last_templates_send_time = 0 ;
7474 unsigned bytes_since_templates_sent = 0 ;
7575
76- std::string
76+ std::string
7777 str ();
7878
7979 void
@@ -93,7 +93,7 @@ struct Session
9393 , client(client)
9494 , ident(ident)
9595 {}
96-
96+
9797 Connection &connection;
9898 Client &client;
9999 std::string ident;
@@ -117,17 +117,17 @@ struct Client
117117 std::string name;
118118 std::map<const ipx_session *, std::unique_ptr<Session>> sessions;
119119
120- std::string
120+ std::string
121121 str ()
122122 {
123123 return name;
124124 }
125125};
126126
127- std::string
127+ std::string
128128Odid::str ()
129129{
130- return session->ident + " (" + std::to_string (odid) + " ) -> " + session->client .name ;
130+ return session->ident + " (" + std::to_string (odid) + " ) -> " + session->client .name ;
131131}
132132
133133std::string
@@ -137,37 +137,37 @@ Session::str()
137137}
138138
139139class Forwarder
140- {
140+ {
141141public:
142142 Forwarder (ipx_ctx_t *log_ctx)
143143 : log_ctx(log_ctx)
144144 {}
145145
146- void
146+ void
147147 set_transport_protocol (TransProto transport_protocol)
148148 {
149149 this ->transport_protocol = transport_protocol;
150150 }
151151
152- void
152+ void
153153 set_forward_mode (ForwardMode forward_mode)
154154 {
155155 this ->forward_mode = forward_mode;
156156 }
157157
158- void
158+ void
159159 set_connection_buffer_size (long number_of_bytes)
160160 {
161161 connection_manager.set_connection_buffer_size (number_of_bytes);
162162 }
163163
164- void
164+ void
165165 set_template_refresh_interval_secs (int number_of_seconds)
166166 {
167167 this ->template_refresh_interval_secs = number_of_seconds;
168168 }
169169
170- void
170+ void
171171 set_template_refresh_interval_bytes (int number_of_bytes)
172172 {
173173 this ->template_refresh_interval_bytes = number_of_bytes;
@@ -275,7 +275,7 @@ class Forwarder
275275 client.sessions [session_info] = std::move (session_ptr);
276276 }
277277
278- void
278+ void
279279 close_session (Client &client, const ipx_session *session_info)
280280 {
281281 auto &session = *client.sessions [session_info];
@@ -295,7 +295,7 @@ class Forwarder
295295 }
296296 }
297297
298- void
298+ void
299299 forward_round_robin (IPFIXMessage &message)
300300 {
301301 int i = 0 ;
@@ -331,7 +331,7 @@ class Forwarder
331331 // / through the session connection and update the state accordingly
332332 // /
333333 // / \return true if there was enough space in the connection buffer, false otherwise
334- bool
334+ bool
335335 send_templates (Session &session, Odid &odid, IPFIXMessage &message)
336336 {
337337 auto templates_snapshot = message.get_templates_snapshot ();
@@ -342,19 +342,19 @@ class Forwarder
342342 MessageBuilder builder;
343343 builder.begin_message (header);
344344
345- fds_tsnapshot_for (templates_snapshot,
345+ fds_tsnapshot_for (templates_snapshot,
346346 [](const fds_template *tmplt, void *data) -> bool {
347347 auto &builder = *(MessageBuilder *)data;
348348 builder.write_template (tmplt);
349349 return true ;
350350 }, &builder);
351-
351+
352352 builder.finalize_message ();
353353
354354 auto lock = session.connection .begin_write ();
355355 if (builder.message_length () > session.connection .writeable ()) {
356- // IPX_CTX_WARNING(log_ctx,
357- // "[%s] Cannot send templates because buffer is full! (need %dB, have %ldB)",
356+ // IPX_CTX_WARNING(log_ctx,
357+ // "[%s] Cannot send templates because buffer is full! (need %dB, have %ldB)",
358358 // odid.str().c_str(), builder.message_length(), session.connection.writeable());
359359 return false ;
360360 }
@@ -371,18 +371,18 @@ class Forwarder
371371 return true ;
372372 }
373373
374- bool
374+ bool
375375 should_refresh_templates (Odid &odid)
376376 {
377377 if (transport_protocol != TransProto::Udp) {
378378 return false ;
379379 }
380380 auto time_since = (std::time (NULL ) - odid.last_templates_send_time );
381- return (time_since > (unsigned )template_refresh_interval_secs)
381+ return (time_since > (unsigned )template_refresh_interval_secs)
382382 || (odid.bytes_since_templates_sent > (unsigned )template_refresh_interval_bytes);
383383 }
384384
385- bool
385+ bool
386386 templates_changed (Odid &odid, IPFIXMessage &message)
387387 {
388388 auto templates_snapshot = message.get_templates_snapshot ();
@@ -392,7 +392,7 @@ class Forwarder
392392 // / Forward message to the client, including templates update if needed
393393 // /
394394 // / \return true if there was enough space in the connection buffer, false otherwise
395- bool
395+ bool
396396 forward_message (Client &client, IPFIXMessage &message)
397397 {
398398 auto &session = *client.sessions [message.session ()];
@@ -409,17 +409,17 @@ class Forwarder
409409 IPX_CTX_INFO (log_ctx, " [%s] Seen new ODID %u" , session.str ().c_str (), message.odid ());
410410 }
411411 auto &odid = session.odids [message.odid ()];
412-
412+
413413 if (should_refresh_templates (odid) || templates_changed (odid, message)) {
414- if (!send_templates (session, odid, message)) {
414+ if (message. get_templates_snapshot () != nullptr && !send_templates (session, odid, message)) {
415415 return false ;
416416 }
417417 }
418-
418+
419419 auto lock = session.connection .begin_write ();
420420 if (message.length () > session.connection .writeable ()) {
421- // IPX_CTX_WARNING(log_ctx,
422- // "[%s] Cannot forward message because buffer is full! (need %dB, have %ldB)",
421+ // IPX_CTX_WARNING(log_ctx,
422+ // "[%s] Cannot forward message because buffer is full! (need %dB, have %ldB)",
423423 // odid.str().c_str(), message.length(), session.connection.writeable());
424424 return false ;
425425 }
0 commit comments