Permalink
Browse files

Moved EPMD symbols into its own package CLERIC-EPMD.

  • Loading branch information...
Markus Flambard
Markus Flambard committed May 25, 2011
1 parent 97da8c0 commit 4d470a6132cdf0b4d7922d62c34dde22db1b327c
Showing with 85 additions and 65 deletions.
  1. +0 −20 src/conditions.lisp
  2. +0 −15 src/constants.lisp
  3. +44 −17 src/epmd.lisp
  4. +18 −10 src/package.lisp
  5. +23 −0 src/remote-node.lisp
  6. +0 −3 src/special-variables.lisp
View
@@ -41,26 +41,6 @@
()
(:documentation "This error is signaled when trying to connect to a node that is unreachable."))
-(define-condition already-registered-on-epmd (error)
- ()
- (:documentation "This error is signaled when trying to register on the EPMD when already registered."))
-
-(define-condition epmd-host-unknown-error (error)
- ;; USOCKET:UNKNOWN-ERROR
- ()
- (:documentation "This error is signaled if the hostname for EPMD is unresolvable."))
-
-(define-condition epmd-unreachable-error (error)
- ;; USOCKET:CONNECTION-REFUSED-ERROR
- ()
- (:documentation "This error is signaled when the EPMD is unreachable."))
-
-
-(define-condition epmd-response-error (error)
- ;; Useful?
- ()
- (:documentation "This error is signaled when the EPMD sends an error response."))
-
(define-condition malformed-message-error (error)
((bytes :reader bytes :initarg :bytes))
(:documentation "This error is signaled when a protocol message is malformed."))
View
@@ -2,11 +2,6 @@
(in-package :cleric)
-;;; Node type tags
-(defconstant +node-type-hidden+ 72)
-(defconstant +node-type-erlang+ 77)
-
-
;;; Node protocol type tags
(defconstant +pass-through+ 112)
(defconstant +protocol-version+ 131)
@@ -77,13 +72,3 @@
"Lowest version of the Erlang distribution protocol supported.")
(defconstant +highest-version-supported+ 5
"Highest version of the Erlang distribution protocol supported.")
-
-;;; EPMD port
-(defconstant +epmd-port+ 4369
- "The default TCP port the EPMD listens on.")
-
-;;; EPMD message tags
-(defconstant +port2-resp+ (char-code #\w))
-(defconstant +alive2-req+ (char-code #\x))
-(defconstant +alive2-resp+ (char-code #\y))
-(defconstant +port-please2-req+ (char-code #\z))
View
@@ -1,9 +1,27 @@
;;;; Functions for querying EPMD (Erlang Port Mapped Daemon)
-(in-package :cleric)
+(in-package :cleric-epmd)
+
+;;; EPMD port
+(defconstant +epmd-port+ 4369
+ "The default TCP port the EPMD listens on.")
+
+;;; EPMD message tags
+(defconstant +port2-resp+ (char-code #\w))
+(defconstant +alive2-req+ (char-code #\x))
+(defconstant +alive2-resp+ (char-code #\y))
+(defconstant +port-please2-req+ (char-code #\z))
+
+;; Node type tags
+(defconstant +node-type-hidden+ 72)
+(defconstant +node-type-erlang+ 77)
(defconstant +protocol-tcpip4+ 0)
+(defvar *epmd-socket* nil
+ "The EPMD socket. NIL if not registered in EPMD.")
+
+
;;;
;;; ALIVE2_REQ
;;
@@ -196,21 +214,30 @@
;;; 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??
-
(defun connect-to-epmd (&optional (host "localhost"))
(usocket:socket-connect host +epmd-port+ :element-type '(unsigned-byte 8)))
+
+
+;;;
+;;; Conditions
+;;;
+
+(define-condition already-registered-on-epmd (error)
+ ()
+ (:documentation "This error is signaled when trying to register on the EPMD when already registered."))
+
+(define-condition epmd-host-unknown-error (error)
+ ;; USOCKET:UNKNOWN-ERROR
+ ()
+ (:documentation "This error is signaled if the hostname for EPMD is unresolvable."))
+
+(define-condition epmd-unreachable-error (error)
+ ;; USOCKET:CONNECTION-REFUSED-ERROR
+ ()
+ (:documentation "This error is signaled when the EPMD is unreachable."))
+
+
+(define-condition epmd-response-error (error)
+ ;; Useful?
+ ()
+ (:documentation "This error is signaled when the EPMD sends an error response."))
View
@@ -73,10 +73,6 @@
#:handshake-failed-error
#:connection-closed-error
#:node-unreachable-error
- #:already-registered-on-epmd
- #:epmd-unreachable-error
- #:epmd-host-unknown-error
- #:epmd-response-error
#:malformed-message-error
#:malformed-external-erlang-term-error
#:untranslatable-lisp-object-error
@@ -105,12 +101,6 @@
#:*erlang-false-is-lisp-nil*
#:*erlang-string-is-lisp-string*
- ;; EPMD Functions
- #:epmd-publish
- #:epmd-published-p
- #:epmd-unpublish
- #:epmd-lookup-node
-
;; Connection functions
#:reg-send
#:send
@@ -119,3 +109,21 @@
#:receive-node-messages
))
+
+(defpackage #:cleric-epmd
+ (:documentation
+ "Functions for querying the EPMD (Erlang Port Mapper Daemon).")
+ (:use #:cl #:cleric)
+ (:export
+
+ #:epmd-publish
+ #:epmd-published-p
+ #:epmd-unpublish
+ #:epmd-lookup-node
+
+ #:already-registered-on-epmd
+ #:epmd-unreachable-error
+ #:epmd-host-unknown-error
+ #:epmd-response-error
+
+ ))
View
@@ -24,6 +24,7 @@
(defmethod socket-stream ((node remote-node))
(usocket:socket-stream (remote-node-socket node)))
+
(defun remote-node-connect (remote-node cookie)
"Connect and perform handshake with a remote node."
(let ((socket
@@ -69,9 +70,31 @@
:full-name full-node-name))
full-node-name))))
+
(defun register-connected-remote-node (remote-node)
(push remote-node *remote-nodes*)
t)
(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??
@@ -5,9 +5,6 @@
(defvar *atom-symbol-package* :keyword
"The package in which atom symbols are interned. Symbols are uninterned if NIL.")
-(defvar *epmd-socket* nil
- "The EPMD socket. NIL if not registered in EPMD.")
-
(defvar *listening-socket* nil
"The listening socket. NIL if not listening.")

0 comments on commit 4d470a6

Please sign in to comment.