Skip to content

Commit 1c73bb8

Browse files
committed
Merge pull request #155 from frenetic-lang/activity
connection activity fixes
2 parents 62dc4fe + cc96a0c commit 1c73bb8

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

async/Async_OpenFlow.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module Chunk : sig
151151
val set_idle_wait : t -> Time.Span.t -> unit
152152
val set_kill_wait : t -> Time.Span.t -> unit
153153

154-
val echo : (t, h, h) Stage.t
154+
val echo : (t, e, e) Stage.t
155155
val handshake : int -> (t, e, h) Stage.t
156156
end
157157

async/Async_OpenFlow0x01.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ module Controller = struct
157157
let open ChunkController in
158158
let stages =
159159
(local (fun t -> t.sub)
160-
(handshake 0x01 >=> echo))
160+
(echo >=> handshake 0x01))
161161
>=> openflow0x01 in
162162
run stages t (listen t.sub)
163163
end

async/Async_OpenFlow0x04.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module Controller = struct
7171
let open ChunkController in
7272
let stages =
7373
(local (fun t -> t.sub)
74-
(handshake 0x04 >=> echo))
74+
(echo >=> handshake 0x04))
7575
>=> openflow0x04 in
7676
run stages t (listen t.sub)
7777

async/Async_OpenFlowChunk.ml

Lines changed: 12 additions & 11 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) }
@@ -107,7 +107,7 @@ module Controller = struct
107107
| None -> assert false
108108
| Some(conn) -> Some(Conn.complete_handshake conn version))
109109

110-
let activity (t:t) ?ver (c_id:Client_id.t) =
110+
let activity (t:t) (c_id:Client_id.t) =
111111
ClientTbl.change t.clients c_id (function
112112
| None -> assert false
113113
| Some(conn) -> Some(Conn.activity conn))
@@ -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(_) ->
@@ -259,6 +259,7 @@ module Controller = struct
259259
let open Header in
260260
match evt with
261261
| `Message (c_id, (hdr, bytes)) ->
262+
Handler.activity t c_id;
262263
begin if hdr.Header.type_code = type_code_echo_request then
263264
(* Echo requests get a reply *)
264265
let hdr = { hdr with type_code = type_code_echo_reply } in
@@ -272,7 +273,7 @@ module Controller = struct
272273
* *)
273274
>>| (function _ -> [])
274275
else if hdr.Header.type_code = type_code_echo_reply then
275-
(* Echo replies get eaten *)
276+
(* Echo replies get eaten. The activity has been recorded above. *)
276277
return []
277278
else
278279
(* All other messages get forwarded *)

0 commit comments

Comments
 (0)