add a check for whether observed boot state is stale or not.
[plewww.git] / planetlab / includes / plc_objects.php
index 1d3b7eb..65abc9a 100644 (file)
@@ -1,6 +1,7 @@
-
 <?php
 
+  // $Id$
+
 function timeDiff ($timestamp,$detailed=false,$n = 0) {
   $now = time();
 
@@ -22,8 +23,8 @@ function timeDiff ($timestamp,$detailed=false,$n = 0) {
   $lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
 
 # Go from decades backwards to seconds
-  $i = sizeof($lengths) - 1;                            # Size of the lengths / periods in case you change them
-  $time = "";                                                                                          # The string we will hold our times in
+  $i = sizeof($lengths) - 1;                           # Size of the lengths / periods in case you change them
+  $time = "";                                          # The string we will hold our times in
   while($i >= $n) {
 # if the difference is greater than the length we are checking... continue
     if ($diff > $lengths[$i-1]) {                              
@@ -270,6 +271,15 @@ class Node extends PlcObject {
   function lastContact() {
     return $this->timeaway($this->last_contact);
   }
+  function stale() {
+    $now = time();
+       $STALE_LENGTH = 60*60;  /* TODO: set by some policy */
+    if ( $this->last_contact + $STALE_LENGTH > $now ) {
+           return False;
+       } else {
+           return True;
+       }
+  }
   function timeaway($val) {
     if ( $val != NULL ) {
       $ret = timeDiff(intval($val));