Author: psmith Date: Fri Feb 9 20:06:30 2007 New Revision: 80
Added: branches/home/psmith/restructure/src/io/nodes.lisp Modified: branches/home/psmith/restructure/src/io/nio.asd branches/home/psmith/restructure/src/utils/nio-utils-package.lisp Log: start of nodes
Modified: branches/home/psmith/restructure/src/io/nio.asd ============================================================================== --- branches/home/psmith/restructure/src/io/nio.asd (original) +++ branches/home/psmith/restructure/src/io/nio.asd Fri Feb 9 20:06:30 2007 @@ -11,6 +11,7 @@ (:file "async-socket" :depends-on ("async-fd")) (:file "nio-server" :depends-on ("async-socket")) (:file "ip-authorisation" :depends-on ("nio-package")) + (:file "nodes" :depends-on ("nio-package")) )
:depends-on (:cffi :event-notification :nio-buffer :nio-compat :nio-utils))
Added: branches/home/psmith/restructure/src/io/nodes.lisp ============================================================================== --- (empty file) +++ branches/home/psmith/restructure/src/io/nodes.lisp Fri Feb 9 20:06:30 2007 @@ -0,0 +1,80 @@ +#| +Copyright (c) 2007 +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +|# +(in-package :nio) + +(declaim (optimize (debug 3) (speed 3) (space 0))) + +;;concept of a remote socket +(defclass node() + ((host :initarg :host + :reader host) + (port :initarg :port + :reader port) + (last-connect-attempt :initform nil + :accessor last-connect-attempt + :documentation "Time we last attempted a connection") + (retry-delay :initform 600 + :accessor retry-delay + :documentation "The delay to wait after the last-connection-attempt before trying to connect again") + (active-conn :initform nil + :accessor active-conn + :documentation "If we are connected to this remote socket this is set to the SM"))) + +(defun node(host port) + (make-instance 'node :host host :port port)) + +;(node-from-socket-repn "192.168.1.1:1234") +(defun node-from-socket-repn(socket) + (let ((colon-idx (search ":" socket))) + (if colon-idx + (node (subseq socket 0 colon-idx) (subseq socket (+ colon-idx 1))) + (error 'parse-error)))) + + +(defmethod print-object ((a-node node) stream) + (with-slots (host port last-connect-attempt retry-delay active-conn) a-node + (format stream "#<NODE :HOST ~A :port ~A :last-connect-attempt ~A :retry-delay ~A :active-conn ~A>" host port last-connect-attempt retry-delay active-conn))) + + +(defparameter *nodes-list* nil + "List of nodes to connect to") + +(defun load-nodes (filename) + (with-open-file (stream filename) + (loop for line = (read-line stream nil nil) do + (push (node-from-socket-repn line) *nodes-list*)))) + + +;;returns floating point (high-res) next allowed connect time +(defun get-next-allowed-connect-time(node) + (if (null (last-connect-attempt node)) + (get-universal-high-res) + (+ (last-connect-attempt node) (retry-delay node)))) + +(defun update-last-connect-attempt(node) + (setf (last-connect-attempt node) (get-universal-high-res))) +
Modified: branches/home/psmith/restructure/src/utils/nio-utils-package.lisp ============================================================================== --- branches/home/psmith/restructure/src/utils/nio-utils-package.lisp (original) +++ branches/home/psmith/restructure/src/utils/nio-utils-package.lisp Fri Feb 9 20:06:30 2007 @@ -29,5 +29,5 @@ (:export
;;utils - format-log + format-log get-universal-high-res ))