From 0072607f65c95c3d037a5d5d6d10e18f5c4786b3 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 17 Oct 2015 20:33:10 -0400 Subject: [PATCH] Factor out demo stack configuration --- demo-config.rkt | 26 ++++++++++++++++++++++++++ fetchurl.rkt | 20 ++------------------ main.rkt | 20 ++------------------ 3 files changed, 30 insertions(+), 36 deletions(-) create mode 100644 demo-config.rkt diff --git a/demo-config.rkt b/demo-config.rkt new file mode 100644 index 0000000..4b065d2 --- /dev/null +++ b/demo-config.rkt @@ -0,0 +1,26 @@ +#lang racket/base +;; Demonstration stack configuration for various hosts. + +(require racket/match) +(require minimart) +(require (only-in mzlib/os gethostname)) +(require "configuration.rkt") + +(provide spawn-demo-config) + +(define (spawn-demo-config) + (spawn (lambda (e s) #f) + (void) + (match (gethostname) + ["skip" + (gestalt-union (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 192 168 1 1) "en0")) + (pub (host-route (bytes 192 168 1 222) 24 "en0")))] + [(or "hop" "walk") + (gestalt-union (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 192 168 1 1) "wlan0")) + (pub (host-route (bytes 192 168 1 222) 24 "wlan0")))] + ["stockholm.ccs.neu.edu" + (gestalt-union (pub (host-route (bytes 129 10 115 94) 24 "eth0")) + (pub (host-route (bytes 192 168 56 222) 24 "vboxnet0")) + (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 129 10 115 1) "eth0")))] + [else + (error 'spawn-demo-config "No setup for hostname ~a" (gethostname))]))) diff --git a/fetchurl.rkt b/fetchurl.rkt index 8ce2478..105bfa0 100644 --- a/fetchurl.rkt +++ b/fetchurl.rkt @@ -2,8 +2,7 @@ (require minimart/demand-matcher) (require minimart/drivers/timer) -(require (only-in mzlib/os gethostname)) -(require "configuration.rkt") +(require "demo-config.rkt") (require "ethernet.rkt") (require "arp.rkt") (require "ip.rkt") @@ -18,22 +17,7 @@ (spawn-ip-driver) (spawn-tcp-driver) (spawn-udp-driver) - -(spawn (lambda (e s) #f) - (void) - (match (gethostname) - ["skip" - (gestalt-union (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 192 168 1 1) "en0")) - (pub (host-route (bytes 192 168 1 222) 24 "en0")))] - ["hop" - (gestalt-union (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 192 168 1 1) "wlan0")) - (pub (host-route (bytes 192 168 1 222) 24 "wlan0")))] - ["stockholm.ccs.neu.edu" - (gestalt-union (pub (host-route (bytes 129 10 115 94) 24 "eth0")) - (pub (host-route (bytes 192 168 56 222) 24 "vboxnet0")) - (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 129 10 115 1) "eth0")))] - [else - (error 'stack-configuration "No setup for hostname ~a" (gethostname))])) +(spawn-demo-config) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/main.rkt b/main.rkt index 685ce32..af9d6af 100644 --- a/main.rkt +++ b/main.rkt @@ -2,8 +2,7 @@ (require minimart/demand-matcher) (require minimart/drivers/timer) -(require (only-in mzlib/os gethostname)) -(require "configuration.rkt") +(require "demo-config.rkt") (require "ethernet.rkt") (require "arp.rkt") (require "ip.rkt") @@ -18,22 +17,7 @@ (spawn-ip-driver) (spawn-tcp-driver) (spawn-udp-driver) - -(spawn (lambda (e s) #f) - (void) - (match (gethostname) - ["skip" - (gestalt-union (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 192 168 1 1) "en0")) - (pub (host-route (bytes 192 168 1 222) 24 "en0")))] - [(or "hop" "walk") - (gestalt-union (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 192 168 1 1) "wlan0")) - (pub (host-route (bytes 192 168 1 222) 24 "wlan0")))] - ["stockholm.ccs.neu.edu" - (gestalt-union (pub (host-route (bytes 129 10 115 94) 24 "eth0")) - (pub (host-route (bytes 192 168 56 222) 24 "vboxnet0")) - (pub (gateway-route (bytes 0 0 0 0) 0 (bytes 129 10 115 1) "eth0")))] - [else - (error 'stack-configuration "No setup for hostname ~a" (gethostname))])) +(spawn-demo-config) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;