public function connect($address = "", $port = "") { if ($this->connected) { $this->close(); } if (empty($port) || !is_integer($port)) { $port = config::$walletPort; } if (empty($address)) { $address = config::$networkInterface; } $address = gethostbyname($address); $this->address = $address; $this->port = $port; $this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($this->socket === false) { gio::log("" . socket_strerror(socket_last_error()), E_USER_WARNING); return false; } $result = @socket_connect($this->socket, $this->address, $this->port); if ($result === false) { gio::log("" . socket_strerror(socket_last_error($this->socket)), E_USER_WARNING); return false; } $this->connectmessage = @socket_read($this->socket, config::$maximumTransmissionLength, PHP_NORMAL_READ); $this->connected = true; return true; }
public static function extract($msg) { if (!is_string($msg)) { return $msg; } gio::log("Extracting message ..."); $extract = json_decode(base64_decode($msg), true); gio::log("... Done Extracting message"); return $extract; }
public static function makepath($arr) { $l = count($arr); $path = ""; for ($i = 1; $i <= $l; $i++) { $path .= $arr[$i - 1]; if ($i != $l) { $path .= DS; } } gio::log("Created file path: {$path}", VERBOSE); return $path; }
private function _processrequest() { if (($this->msgsock = @socket_accept($this->sock)) === false) { gio::log("socket_accept() failed: reason: " . socket_strerror(socket_last_error($this->sock)), E_USER_ERROR); break; } gio::log("\nSocket: CONNECTION RECEIVED", VERBOSE); $this->_welcome(); do { if (false === ($buf = @socket_read($this->msgsock, config::$maximumTransmissionLength, PHP_NORMAL_READ))) { gio::log("socket_read() failed: reason: " . socket_strerror(socket_last_error($this->msgsock)), E_USER_WARNING); break; } if (!($buf = trim($buf))) { continue; } gio::log("NEW REQUEST RECEIVED", VERBOSE); if ($buf == 'quit') { gio::log("Socket: Connection terminated by client!", VERBOSE); break; } if ($buf == 'restart') { $this->restart = true; gio::log("Socket: Restarting the server !!!", VERBOSE); $buf = 'shutdown'; } if ($buf == 'shutdown') { gio::output("Processing request to stop the server ..."); self::_out("Shuting down..."); self::_flush(); $this->stop = true; break; } if (!$this->stop) { $sockreply = Gmsg::process($buf); $this->_out($sockreply); $this->_flush(); gio::log("Socket: REPLY SENT\n", VERBOSE); } else { $this->_out("...Terminating Server Process..."); break; } } while (true); socket_close($this->msgsock); unset($this->msgsock); gio::log("\nSocket: CONNECTION ENDED", VERBOSE); }
public static function readrawfile($file) { gio::log("Reading rawfile: {$file} ...", VERBOSE); $ret = @file_get_contents($file); if (!$ret) { gio::log("... Error reading rawfile: {$file} ...", E_USER_WARNING); } else { gio::log("... Done reading rawfile: {$file}", VERBOSE); } return $ret; }
private static function hash($in) { $h = new ghash("{$in}", 20); $token = ''; try { $token = $h->hash(); } catch (Exception $e) { gio::log('ERROR: ' . $e->getMessage()); } unset($h); return $token; }
public static function pullcoins() { $m = Gmsg::create(Gmsg::prepare(GsonCrypt::sign(Gmsg::create(array('account' => config::$accountId))), 'pullcoins', config::$bankId)); $net = new Gnet(); $r = $net->send($m); $v = GsonCrypt::verify($r, config::$bankId); if (!$v) { $status = 0; gio::log("Unable to verify response from bank while pulling coins", E_USER_WARNING); } else { $v = Gmsg::extract($v); if (!$v) { $status = 0; gio::log("Unable to understand the response while pulling coins", E_USER_WARNING); } else { $status = $v['status']; $res = $v['response']; } } if (!$status) { gio::output("Could not pull eCash from bank"); } else { if (!is_array($res)) { gio::output("Could not pull eCash from bank"); } else { $check = 1; foreach ($res as $val => $ccs) { foreach ($ccs as $id => $coin) { $res[$val][$id]['secret'] = GsonCrypt::unseal($coin['secret']); if (!$res[$val][$id]['secret']) { $check = 0; } } } if (!$check) { gio::output("Could not get the secret of some eCash"); } } if (is_array($res) && count($res)) { $old = storage::load(); if (!$old) { $old = array(); } foreach ($res as $val => $ccs) { foreach ($ccs as $id => $coin) { $val = $coin['value']; $old[$val][$id] = $coin; } } storage::save($old); } } }
private static function hash($in) { switch (config::$minestrength) { case 1: $s = 22; break; case 2: $s = 25; break; case 3: $s = 28; break; case 4: $s = 32; break; case 5: $s = 35; break; case 6: $s = 40; break; case 7: $s = 50; default: $s = 20; } $h = new ghash("{$in}", $s); $token = ''; try { $token = $h->hash(); } catch (Exception $e) { gio::log('ERROR: ' . $e->getMessage()); } unset($h); return $token; }
public function parseStamp($stamp) { if (!$stamp) { gio::log('Stamp "' . $stamp . '" is not valid.', E_USER_ERROR); } $items = preg_split('/:/', $stamp); if (count($items) < 7) { gio::log('Stamp "' . $stamp . '" is not valid.', E_USER_ERROR); } $this->setVersion($items[0]); $this->setBits($items[1]); $this->setDate($items[2]); $this->setResource($items[3]); $this->setExtension($items[4]); $this->setSalt($items[5]); $this->setSuffix($items[6]); }
public static function cryptoInstalled() { gio::log("Checking Cryptographic library Installation ...", VERBOSE); if (function_exists("openssl_pkey_new")) { gio::log("... Cryptographic library Installation OK", VERBOSE); return true; } gio::log("... Cryptographic library Not Installed ...", E_USER_WARNING); return false; }