Permalink
Browse files

Added file local-node.lisp and removed direct access to *THIS-NODE*, …

…providing a new SETF-able function THIS-NODE instead.
  • Loading branch information...
1 parent 9ee744e commit a08fe4f57b8c82e99b0d817398792ecaeb2b5779 Markus Flambard committed May 26, 2011
Showing with 49 additions and 30 deletions.
  1. +6 −0 cleric.asd
  2. +1 −2 src/epmd.lisp
  3. +1 −1 src/erlang-pid.lisp
  4. +2 −2 src/handshake.lisp
  5. +36 −0 src/local-node.lisp
  6. +3 −1 src/packages.lisp
  7. +0 −21 src/remote-node.lisp
  8. +0 −3 src/special-variables.lisp
View
@@ -16,6 +16,8 @@
((:file "packages")
(:file "listen"
:depends-on ("packages"))
+ (:file "local-node"
+ :depends-on ("packages"))
(:file "macros"
:depends-on ("packages"))
(:file "generic-functions"
@@ -24,6 +26,7 @@
(:file "remote-node"
:depends-on ("packages"
"listen"
+ "local-node"
"atom-cache"
"special-variables"))
(:file "conditions"
@@ -57,6 +60,7 @@
"bops"))
(:file "epmd"
:depends-on ("packages"
+ "local-node"
"conditions"
"remote-node"
"bops"
@@ -82,6 +86,7 @@
"erlang-tuple"))
(:file "handshake"
:depends-on ("packages"
+ "local-node"
"conditions"
"bops"
"constants"
@@ -144,6 +149,7 @@
"bops"))
(:file "erlang-pid"
:depends-on ("packages"
+ "local-node"
"constants"
"conditions"
"special-variables"
View
@@ -195,8 +195,7 @@
(error 'unreachable-error))))
(epmd (usocket:socket-stream socket)))
(write-sequence
- (make-alive2-request (cleric::node-name *this-node*)
- (listening-port))
+ (make-alive2-request (node-name (this-node)) (listening-port))
epmd)
(finish-output epmd)
(let ((creation (read-alive2-response epmd)))
View
@@ -25,7 +25,7 @@
(defun make-pid ()
"Create a new Erlang PID."
(make-instance 'erlang-pid
- :node (make-symbol *this-node*)
+ :node (make-symbol (this-node))
:id (generate-new-pid-id)
:serial #(0 0 0 0) ;; What to set here?
:creation 1)) ;; What to set here?
View
@@ -174,7 +174,7 @@
(defun perform-client-handshake (stream cookie)
(write-sequence (make-name-message +highest-version-supported+
(capability-flags)
- *this-node*)
+ (this-node))
stream)
(finish-output stream)
(let ((status (read-status-message stream)))
@@ -218,7 +218,7 @@
(write-sequence (make-challenge-message +highest-version-supported+
(capability-flags)
challenge
- *this-node*)
+ (this-node))
stream)
(finish-output stream)
(multiple-value-bind (new-challenge digest)
View
@@ -0,0 +1,36 @@
+(in-package :cleric)
+
+(defvar *this-node* "lispnode@localhost"
+ "The name and host for this node.")
+
+
+(defun this-node ()
+ *this-node*)
+
+(defun (setf this-node) (node-name)
+ ;; TODO: Add sanity checks.
+ ;; The node name should be valid.
+ ;; It should not be possible to change node name while connected to other
+ ;; nodes and/or registered on the EPMD.
+ (setf *this-node* node-name))
+
+
+;;;
+;;; Utility functions
+;;;
+
+(defun node-name (node-string)
+ "Return the name part of a node identifier"
+ ;; All characters up to a #\@ is the name
+ (let ((pos (position #\@ node-string)))
+ (if pos
+ (subseq node-string 0 pos)
+ node-string)))
+
+(defun node-host (node-string)
+ "Return the host part of a node identifier"
+ ;; All characters after a #\@ is the host
+ (let ((pos (position #\@ node-string)))
+ (if pos
+ (subseq node-string (1+ pos))
+ "localhost"))) ;; OK with localhost??
View
@@ -89,6 +89,9 @@
#:listening-port
#:start-listening
#:stop-listening
+ #:this-node
+ #:node-name
+ #:node-host
;; Conditions
#:not-implemented-error
@@ -115,7 +118,6 @@
;; Special variables
#:*atom-symbol-package*
- #:*this-node*
#:*remote-nodes*
#:*lisp-t-is-erlang-true*
#:*lisp-nil-is-erlang-empty-list*
View
@@ -77,24 +77,3 @@
(defun find-connected-remote-node (node-name) ;; Make NODE-NAME a node designator
(find node-name *remote-nodes* :key #'remote-node-name :test #'string=)) ;; Perhaps also check full name?
-
-
-;;;
-;;; Helper functions
-;;;
-
-(defun node-name (node-string)
- "Return the name part of a node identifier"
- ;; All characters up to a #\@ is the name
- (let ((pos (position #\@ node-string)))
- (if pos
- (subseq node-string 0 pos)
- node-string)))
-
-(defun node-host (node-string)
- "Return the host part of a node identifier"
- ;; All characters after a #\@ is the host
- (let ((pos (position #\@ node-string)))
- (if pos
- (subseq node-string (1+ pos))
- "localhost"))) ;; OK with localhost??
@@ -8,9 +8,6 @@
(defvar *listening-socket* nil
"The listening socket. NIL if not listening.")
-(defvar *this-node* "lispnode@localhost"
- "The name and host for this node.")
-
(defvar *pid-id-counter* 0)
(defvar *remote-nodes* (list)

0 comments on commit a08fe4f

Please sign in to comment.