@@ -46,16 +46,16 @@ use std::sync::{Arc, RwLock};
4646use std:: thread;
4747
4848use redis;
49- use time :: precise_time_ns;
49+ use util :: precise_time_ns;
5050
5151use flow_tracker:: { FlowNoSrcPort , FLOW_CLIENT_LOG } ;
5252use protobuf:: Message ;
5353use signalling:: StationToDetector ;
5454
55- const S2NS : u64 = 1000 * 1000 * 1000 ;
55+ const S2NS : u128 = 1000 * 1000 * 1000 ;
5656// time to add beyond original timeout if a session is still receiving packets
5757// that need to be forwarded to the data plane proxying logic. (300 s = 5 mins)
58- const TIMEOUT_PHANTOMS_NS : u64 = 300 * S2NS ;
58+ const TIMEOUT_PHANTOMS_NS : u128 = 300 * S2NS ;
5959
6060// We _can_ filter by phantom port if we so choose, and randomize the port that
6161// the clients connect to. However we are currently using exclusively port 443.
@@ -93,13 +93,13 @@ pub struct SessionDetails {
9393 pub client_ip : IpAddr ,
9494 pub phantom_ip : IpAddr ,
9595 pub phantom_port : u16 ,
96- timeout : u64 ,
96+ timeout : u128 ,
9797}
9898
9999impl SessionDetails {
100100 // This function parses acceptable Session Details and returns an error if
101101 // the details provided do not fit current requirements for parsing
102- pub fn new ( client_ip : & str , phantom_ip : & str , timeout : u64 ) -> SessionResult {
102+ pub fn new ( client_ip : & str , phantom_ip : & str , timeout : u128 ) -> SessionResult {
103103 let phantom: IpAddr = match phantom_ip. parse ( ) {
104104 Ok ( ip) => ip,
105105 Err ( _) => return Err ( SessionError :: InvalidPhantom ) ,
@@ -141,7 +141,7 @@ impl From<&StationToDetector> for SessionResult {
141141 fn from ( s2d : & StationToDetector ) -> Self {
142142 let source = s2d. get_client_ip ( ) ;
143143 let phantom = s2d. get_phantom_ip ( ) ;
144- SessionDetails :: new ( source, phantom, s2d. get_timeout_ns ( ) )
144+ SessionDetails :: new ( source, phantom, u128 :: from ( s2d. get_timeout_ns ( ) ) )
145145 }
146146}
147147
@@ -173,7 +173,7 @@ pub struct SessionTracker {
173173 // Note: In the future phantom port can be optionally added to the key
174174 // string to further filter incoming connections. This is left off for now
175175 // to allow for testing of source-refraction.
176- pub tracked_sessions : Arc < RwLock < HashMap < String , u64 > > > ,
176+ pub tracked_sessions : Arc < RwLock < HashMap < String , u128 > > > ,
177177}
178178
179179impl Default for SessionTracker {
@@ -253,7 +253,7 @@ impl SessionTracker {
253253 self . try_update_session_timeout ( key, TIMEOUT_PHANTOMS_NS ) ;
254254 }
255255
256- fn try_update_session_timeout ( & mut self , key : String , extra_time : u64 ) {
256+ fn try_update_session_timeout ( & mut self , key : String , extra_time : u128 ) {
257257 // Get writable map
258258 let mut mmap = self . tracked_sessions . write ( ) . expect ( "RwLock broken" ) ;
259259
@@ -313,7 +313,7 @@ impl SessionTracker {
313313}
314314
315315// No returns in this function so that it runs for the lifetime of the process.
316- fn ingest_from_pubsub ( map : Arc < RwLock < HashMap < String , u64 > > > ) {
316+ fn ingest_from_pubsub ( map : Arc < RwLock < HashMap < String , u128 > > > ) {
317317 let mut con = get_redis_conn ( ) ;
318318 let mut pubsub = con. as_pubsub ( ) ;
319319 pubsub
@@ -400,6 +400,8 @@ mod tests {
400400 use signalling:: StationToDetector ;
401401 use std:: { thread, time} ;
402402
403+ const S2NS_U64 : u64 = 1000 * 1000 * 1000 ;
404+
403405 #[ test]
404406 #[ ignore] // Requires redis to run properly.
405407 fn test_session_tracker_pubsub ( ) {
@@ -411,18 +413,18 @@ mod tests {
411413 // redis::cmd("PUBLISH").arg("dark_decoy_map").arg(octs).execute(&self.redis_conn);
412414 let st = SessionTracker :: new ( ) ;
413415
414- let test_tuples = [
416+ let test_tuples: [ ( & str , & str , u64 ) ; 8 ] = [
415417 // (client_ip, phantom_ip, timeout)
416418 ( "172.128.0.2" , "8.0.0.1" , 1 ) , // timeout immediately
417- ( "192.168.0.1" , "10.10.0.1" , 5 * S2NS ) ,
418- ( "192.168.0.1" , "192.0.0.127" , 5 * S2NS ) ,
419- ( "" , "2345::6789" , 5 * S2NS ) ,
419+ ( "192.168.0.1" , "10.10.0.1" , 5 * S2NS_U64 ) ,
420+ ( "192.168.0.1" , "192.0.0.127" , 5 * S2NS_U64 ) ,
421+ ( "" , "2345::6789" , 5 * S2NS_U64 ) ,
420422 // duplicate with shorter timeout should not drop
421- ( "2601::123:abcd" , "2001::1234" , 5 * S2NS ) ,
422- ( "::1" , "2001::1234" , S2NS ) ,
423+ ( "2601::123:abcd" , "2001::1234" , 5 * S2NS_U64 ) ,
424+ ( "::1" , "2001::1234" , S2NS_U64 ) ,
423425 // duplicate with long timeout should prevent drop
424426 ( "7.0.0.2" , "8.8.8.8" , 1 ) ,
425- ( "7.0.0.2" , "8.8.8.8" , 5 * S2NS ) ,
427+ ( "7.0.0.2" , "8.8.8.8" , 5 * S2NS_U64 ) ,
426428 ] ;
427429
428430 st. spawn_update_thread ( ) ;
@@ -500,7 +502,7 @@ mod tests {
500502 } ;
501503 // assert_eq!(entry.0, sd.client_ip.to_string());
502504 assert_eq ! ( entry. 1 , sd. phantom_ip. to_string( ) ) ;
503- assert_eq ! ( entry. 2 , sd. timeout)
505+ assert_eq ! ( u128 :: from ( entry. 2 ) , sd. timeout)
504506 }
505507
506508 for entry in & test_tuples_bad {
@@ -574,19 +576,19 @@ mod tests {
574576 let test_tuples = [
575577 // (client_ip, phantom_ip, timeout)
576578 ( "172.128.0.2" , "8.0.0.1" , 1 , false ) , // timeout immediately
577- ( "192.168.0.1" , "10.10.0.1" , 5 * S2NS , true ) ,
578- ( "192.168.0.1" , "192.0.0.127" , 5 * S2NS , true ) ,
579+ ( "192.168.0.1" , "10.10.0.1" , 5 * S2NS_U64 , true ) ,
580+ ( "192.168.0.1" , "192.0.0.127" , 5 * S2NS_U64 , true ) ,
579581 // client registering with v4 will also create registrations for v6 just in-case
580- ( "192.168.0.1" , "2801::1234" , 5 * S2NS , true ) ,
582+ ( "192.168.0.1" , "2801::1234" , 5 * S2NS_U64 , true ) ,
581583 // duplicate with shorter timeout should not drop
582- ( "2601::123:abcd" , "2001::1234" , 5 * S2NS , true ) ,
583- ( "::1" , "2001::1234" , S2NS , true ) ,
584+ ( "2601::123:abcd" , "2001::1234" , 5 * S2NS_U64 , true ) ,
585+ ( "::1" , "2001::1234" , S2NS_U64 , true ) ,
584586 // duplicate with long timeout should prevent drop
585587 ( "7.0.0.2" , "8.8.8.8" , 1 , true ) ,
586- ( "7.0.0.2" , "8.8.8.8" , 5 * S2NS , true ) ,
588+ ( "7.0.0.2" , "8.8.8.8" , 5 * S2NS_U64 , true ) ,
587589 ] ;
588590 for entry in & test_tuples {
589- let s1 = SessionDetails :: new ( entry. 0 , entry. 1 , entry. 2 ) . unwrap ( ) ;
591+ let s1 = SessionDetails :: new ( entry. 0 , entry. 1 , u128 :: from ( entry. 2 ) ) . unwrap ( ) ;
590592 st. insert_session ( s1) ;
591593 }
592594
0 commit comments