Skip to content

Commit aa83da9

Browse files
committed
activity: rework handshake/activity distinction
Treat the handshake state as something separate and orthogonal to tracking activity. Now it's possible to detect an idle connection that has not completed a handshake and kill it if necessary.
1 parent 625b9e2 commit aa83da9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

async/Async_OpenFlowChunk.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ module Controller = struct
3333

3434
module Conn = struct
3535
type t = {
36-
state : [ `Handshake | `Active | `Idle | `Kill ];
36+
state : [ `Active | `Idle | `Kill ];
3737
version : int option;
3838
state_entered : Time.t;
3939
last_activity : Time.t
4040
}
4141

4242
let create () : t =
4343
let now = Time.now () in
44-
{ state = `Handshake
44+
{ state = `Active
4545
; version = None
4646
; state_entered = now
4747
; last_activity = now
4848
}
4949

5050
let activity (t:t) : t =
5151
let t = { t with last_activity = Time.now () } in
52-
if t.state = `Active then
53-
t
54-
else
52+
if t.state = `Idle then
5553
{ t with state = `Active; state_entered = t.last_activity }
54+
else
55+
t
5656

5757
let complete_handshake (t:t) (version:int) : t =
5858
activity { t with version = Some(version) }
@@ -194,8 +194,8 @@ module Controller = struct
194194
let has_client_id t c_id =
195195
Platform.has_client_id t.platform c_id &&
196196
match ClientTbl.find t.clients c_id with
197-
| Some(conn) -> not (conn.Conn.state = `Handshake)
198-
| _ -> false
197+
| Some({ Conn.version = Some(_) }) -> true
198+
| _ -> false
199199

200200
let send t c_id m =
201201
Platform.send t.platform c_id m
@@ -228,7 +228,7 @@ module Controller = struct
228228
| `Message (c_id, msg) ->
229229
begin match ClientTbl.find t.clients c_id with
230230
| None -> assert false
231-
| Some({ Conn.state = `Handshake }) ->
231+
| Some({ Conn.version = None }) ->
232232
let hdr, bits = msg in
233233
begin
234234
if not (hdr.type_code = type_code_hello) then begin
@@ -247,7 +247,7 @@ module Controller = struct
247247
| `Disconnect (c_id, exn) ->
248248
begin match ClientTbl.find t.clients c_id with
249249
| None -> assert false
250-
| Some({ Conn.state = `Handshake }) ->
250+
| Some({ Conn.version = None }) ->
251251
ClientTbl.remove t.clients c_id;
252252
return []
253253
| Some(_) ->

0 commit comments

Comments
 (0)