function forwardObjects() { global $db, $config; global $page; if (!$console && $this->getBool('use_for_outgoing')) { debug("node {$this->id} is not used for outgoing sync"); return; } debug("FORWARDING TO ", $this->get("node_id")); $rpc = new rpc_Utils(); if ($config['debug']) { $rpc->debug = true; } $timestamp = $db->getTimestampTz(); $remoteId = $this->get('node_id'); $url = $this->get('url'); // remove trailing '/' while (substr($url, -1) == '/') { $url = substr($url, 0, -1); } // calculate chunking $thisChunk = 1; // do XML-RPC conversation $objectsSent = 0; $more = sotf_NodeObject::countForwardObjects($remoteId); if (!$more) { debug("No new objects to send"); } while ($more) { $db->begin(true); $modifiedObjects = sotf_NodeObject::getForwardObjects($remoteId, $this->objectsPerRPCRequest); $more = sotf_NodeObject::countForwardObjects($remoteId); $chunkInfo = array('this_chunk' => $thisChunk, 'from_node' => $config['nodeId'], 'objects_remaining' => $more); debug("chunk info", $chunkInfo); debug("number of sent objects", count($modifiedObjects)); $objectsSent = $objectsSent + count($modifiedObjects); $objs = array($chunkInfo, $modifiedObjects); $response = $rpc->call($url . "/xmlrpcServer.php/forward/{$thisChunk}", 'sotf.forward', $objs); // error handling if (is_null($response)) { $db->rollback(); return; } $db->commit(); $replyInfo = $response[0]; debug("replyInfo", $replyInfo); $thisChunk++; } debug("total number of objects sent", $objectsSent); //$this->log($console, "number of updated objects: " .count($updatedObjects)); }
function sync($console = false) { global $db, $page, $config; $remoteId = $this->get('node_id'); if (!$console && $this->get('use_for_outgoing') != 't') { debug("node {$remoteId} is not used for outgoing sync"); return; } debug("SYNCing with ", $this->get("node_id")); $rpc = new rpc_Utils(); if ($config['debug']) { $rpc->debug = true; } $timestamp = $db->getTimestampTz(); $url = $this->getUrl(); // remove trailing '/' while (substr($url, -1) == '/') { $url = substr($url, 0, -1); } // collect local data to send $localNode = sotf_Node::getLocalNode(); // check if url is correct... if ($localNode->get('url') != $config['rootUrl']) { $localNode->set('url', $config['rootUrl']); $localNode->update(); } //debug("localNode", $localNode); //debug("neighbour", $this); $localNodeData = $localNode->getAll(); // calculate chunking $thisChunk = 1; // do XML-RPC conversation $objectsSent = 0; $more = sotf_NodeObject::countModifiedObjects($remoteId); if (!$more) { debug("No new objects to send"); } while ($more) { $db->begin(true); $modifiedObjects = sotf_NodeObject::getModifiedObjects($remoteId, $this->objectsPerRPCRequest); $remaining = sotf_NodeObject::countModifiedObjects($remoteId); if (count($modifiedObjects) == 0 && $remaining > 0) { logError("DATA integrity problem", "{$remaining} objects remained in sotf_object_status after sync"); } if ($remaining == 0 || count($modifiedObjects) == 0) { $more = false; } else { $more = true; } $chunkInfo = array('this_chunk' => $thisChunk, 'node' => $localNodeData, 'objects_remaining' => $remaining); debug("chunk info", $chunkInfo); debug("number of sent objects", count($modifiedObjects)); $objectsSent = $objectsSent + count($modifiedObjects); $objs = array($chunkInfo, $modifiedObjects); $response = $rpc->call($url . "/xmlrpcServer.php/sync/{$thisChunk}", 'sotf.sync', $objs); // error handling $replyInfo = $response[0]; debug("replyInfo", $replyInfo); if (is_null($response) || $replyInfo['error']) { $this->set('errors', $this->get('errors') + 1); $this->update(); $db->rollback(); return; } $db->commit(); // save received data $thisChunk++; } debug("total number of objects sent", $objectsSent); //$this->log($console, "number of updated objects: " .count($updatedObjects)); // save node and neighbour stats if ($error) { $this->set('errors', $this->get('errors') + 1); } else { $this->set('success', $this->get('success') + 1); } $this->set('last_sync_out', $timestamp); $localNode->set('last_sync_out', $timestamp); // take out from pending nodes if ($this->get('pending_url')) { $remoteNode = sotf_Node::getNodeById($remoteId); // TODO: problem is that if this is first sync or one-way connection, then object fro remote node may not exist if ($remoteNode) { $this->set('pending_url', ''); } $localNode->set('neighbours', $this->getNeighbourString()); } $this->update(); $localNode->update(); }
function startStreaming() { global $config, $tamburine; if (!$this->localPlaylist) { $this->makeLocalPlaylist(); } if ($config['tamburineURL']) { // tamburine-based streaming if ($_SESSION['playlist_id']) { //TODO? kill old stream } $rpc = new rpc_Utils(); //$rpc->debug = true; $response = $rpc->call($config['tamburineURL'], 'setpls', $this->localPlaylist); if (is_null($response)) { debug("no reply from tamburine server"); } else { $this->url = $response[0]; $id = $response[1]; $_SESSION['playlist_id'] = $id; } } else { // command-line streaming $this->url = 'http://' . $config['iceServer'] . ':' . $config['icePort'] . '/' . $this->getTmpId() . "\n"; //$url = preg_replace('/^.*\/repository/', 'http://sotf2.dsd.sztaki.hu/node/repository', $filepath); // TODO: calculate bitrate from all files... $bitrate = $this->audioFiles[0]['bitrate']; if (!$bitrate) { $bitrate = 24; } $this->cmdStart($this->localPlaylist, $this->getTmpId(), $bitrate); //$this->cmdStart2($bitrate); } }
function runQuery($query) { global $sotfSite; $rpc = new rpc_Utils(); $url = $sotfSite . "xmlrpcServer.php"; $objs = array($query); return $rpc->call($url, 'portal.query', $objs); }
function sync($console = false) { global $sotfVars; // tunable things $objectsPerRPCRequest = 100; global $page; if (!$console && $this->getBool('use_for_outgoing')) { debug("node {$this->id} is not used for outgoing sync"); return; } debug("SYNCing with ", $this->get("node_id")); $rpc = new rpc_Utils(); if ($config['debug']) { $rpc->debug = true; } $timestamp = $this->db->getTimestampTz(); $remoteId = $this->get('node_id'); $url = $this->getUrl(); // remove trailing '/' while (substr($url, -1) == '/') { $url = substr($url, 0, -1); } // collect local data to send $localNode = sotf_Node::getLocalNode(); //debug("localNode", $localNode); debug("neighbour", $this); $localNodeData = $localNode->getAll(); // check if url is correct... $localNodeData['url'] = $config['rootUrl']; // calculate chunking $currentStamp = $sotfVars->get('sync_stamp', 0); $lastSyncStamp = $this->lastSyncStamp(); $count = sotf_NodeObject::countModifiedObjects($remoteId, $lastSyncStamp); $numChunks = ceil($count / $objectsPerRPCRequest); if ($numChunks == 0) { $numChunks = 1; } $thisChunk = 1; $chunkInfo = array("old_stamp" => $lastSyncStamp, "current_stamp" => $currentStamp, "num_chunks" => $numChunks, 'this_chunk' => $thisChunk); debug("1st chunk info", $chunkInfo); // do XML-RPC conversation $objectsSent = 0; $objectsReceived = 0; while ($thisChunk <= $numChunks) { if ($thisChunk == $numChunks) { // last chunk: no limits $objectsPerRPCRequest = 100 * $objectsPerRPCRequest; } $modifiedObjects = sotf_NodeObject::getModifiedObjects($remoteId, $lastSyncStamp, $objectsSent + 1, $objectsPerRPCRequest); $chunkInfo['this_chunk'] = $thisChunk; debug("chunk info", $chunkInfo); //debug("number of sent objects", count($modifiedObjects)); $objectsSent = $objectsSent + count($modifiedObjects); $objs = array($chunkInfo, $localNodeData, $modifiedObjects); $response = $rpc->call($url . '/xmlrpcServer.php', 'sotf.sync', $objs); // error handling if (is_null($response)) { $this->set('errors', $this->get('errors') + 1); $this->update(); return; } // save received data $chunkInfo = $response[0]; $newObjects = $response[1]; $objectsReceived = $objectsReceived + count($newObjects); debug("number of received objects", count($newObjects)); if (count($newObjects) > 0) { $updatedObjects = sotf_NodeObject::saveModifiedObjects($newObjects); } $thisChunk++; } debug("total number of objects sent", $objectsSent); debug("total number of objects received", $objectsReceived); //$this->log($console, "number of updated objects: " .count($updatedObjects)); // save last_sync $this->set('success', $this->get('success') + 1); $this->set('last_sync_out', $timestamp); $this->saveSyncStatus($timestamp, $currentStamp); // send receipt of successful sync?? }
<?php require "init.inc.php"; require_once $config['classdir'] . "/rpc_Utils.class.php"; $rpc = new rpc_Utils(); $rpc->debug = true; //$response = $rpc->call($config['rootUrl'] . "/xmlrpcServer.php", 'sotf.cv.listnames', ''); $response = $rpc->call($config['rootUrl'] . "/xmlrpcServer.php", 'sotf.cv.get', array('topics', 1, 'fr')); print "<pre>"; print_r($response); print "</pre>"; /* $tree = $repository->getTree(1, 'en'); print "<pre>"; print_r($tree); print "</pre>"; exit; */ /* require_once($config['classdir'] . "/rpc_Utils.class.php"); $rpc = new rpc_Utils; $rpc->debug = true; $response = $rpc->call($config['tamburineURL'], 'version', ''); */ /* require_once($config['classdir'] . '/unpackXML.class.php'); $myPack = new unpackXML($config['basedir'] . "/metasample.txt");