No longer using URIs for internal address representation.
[sam.git] / sam.scm
diff --git a/sam.scm b/sam.scm
index 110a55c..17c6f41 100644 (file)
--- a/sam.scm
+++ b/sam.scm
@@ -1,13 +1,16 @@
 ;; Simple Actor Machine
 ;;
-;; Houses a population of actors which can communicate using messages
-;; with actors on the same machine or other machines via the network.
+;; A virtual machine which houses a population of actors which can
+;; communicate using messages with actors on the same machine or other
+;; machines via the network.
 
 (module sam
     (boot-sam
      make-actor
      send-message
-     send-message-later)
+     send-message-later
+     address->string
+     string->address)
 
   (import scheme
           (chicken base)
@@ -19,7 +22,6 @@
           srfi-18 ; threads
           srfi-69 ; hash-table
           uuid ; ids for actors
-          uri-generic
           udp
           fifo)
 
   (define sam-port 8000)
 
   (define (make-address host port id)
-    (uri->string
-     (make-uri #:scheme "actor"
-               #:host host
-               #:port port
-               #:path (list '/ id))))
+    (list id host port))
 
   (define (make-local-address . args)
     (make-address sam-host
                       (car args))))
   
   (define (address-id address)
-    (cadr (uri-path (uri-reference address))))
-
-  (define address->uri uri-reference)
+    (car address))
+  (define (address-host address)
+    (cadr address))
+  (define (address-port address)
+    (caddr address))
+  (define (address->string address)
+    (with-output-to-string
+      (lambda () (write address))))
+  (define (string->address str)
+    (with-input-from-string str read))
 
   (define (address-local? address)
-    (let ((uri (address->uri address)))
-      (and (equal? (uri-host uri) sam-host)
-           (equal? (uri-port uri) sam-port))))
+    (and (equal? (address-host address) sam-host)
+         (equal? (address-port address) sam-port)))
 
   (define actor-table (make-hash-table))
 
 
   (define (send-network-message address . message)
     (let ((s (udp-open-socket))
-          (uri (address->uri address))
           (packet (with-output-to-string
                     (lambda ()
                       (write (cons address message))))))
       (udp-bind! s #f 0)
       (udp-connect! s
-                    (uri-host uri)
-                    (uri-port uri))
+                    (address-host address)
+                    (address-port address))
       (udp-send s packet)
       (udp-close-socket s)))
 
        (let ((s (udp-open-socket*)))
          (udp-bind! s #f sam-port)
          (let loop ()
-           (let-values (((n str) (udp-recv s 1024)))
+           (let-values (((n str) (udp-recv s 65536)))
              (match (with-input-from-string str read)
                ((address message ...)
                 (apply send-message (cons address message)))