This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
38 changed files
with
1,216 additions
and
632 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,14 @@ before_install: | |
- brew install [email protected] openexr | ||
- brew install ethereum/ethereum/ethereum ipfs | ||
|
||
- rm -rf ~/.ipfs | ||
- ipfs init | ||
- ipfs daemon & | ||
|
||
- git clone https://github.com/mfranciszkiewicz/golem-hyperdrive --depth 1 | ||
- cd golem-hyperdrive && npm install --save && cd .. | ||
- node golem-hyperdrive\src\main.js & | ||
|
||
- sudo pip install --upgrade pip setuptools packaging pytest mock | ||
- pip install https://github.com/golemfactory/golem/wiki/wheels/sip-4.19-cp27-cp27m-macosx_10_12_x86_64.whl | ||
- pip install https://github.com/golemfactory/golem/wiki/wheels/PyQt5-5.7.1-cp27-cp27m-macosx_10_12_x86_64.whl | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import json | ||
|
||
import requests | ||
|
||
from golem.resource.client import IClient, ClientOptions | ||
|
||
|
||
class HyperdriveClient(IClient): | ||
|
||
CLIENT_ID = 'hyperg' | ||
VERSION = 1.0 | ||
|
||
def __init__(self, port=3292, host='127.0.0.1', timeout=None): | ||
super(HyperdriveClient, self).__init__() | ||
|
||
# destination address | ||
self.host = host | ||
self.port = port | ||
# connection / read timeout | ||
self.timeout = timeout | ||
|
||
# default POST request headers | ||
self._url = 'http://{}:{}/api'.format(self.host, self.port) | ||
self._headers = {'content-type': 'application/json'} | ||
|
||
@classmethod | ||
def build_options(cls, node_id, **kwargs): | ||
return ClientOptions(cls.CLIENT_ID, cls.VERSION) | ||
|
||
def diagnostics(self, *args, **kwargs): | ||
raise NotImplementedError() | ||
|
||
def id(self, client_options=None, *args, **kwargs): | ||
response = self._request(command='id') | ||
return response['id'] | ||
|
||
def add(self, files, client_options=None, **kwargs): | ||
response = self._request( | ||
command='upload', | ||
id=kwargs.get('id'), | ||
files=files | ||
) | ||
return response['hash'] | ||
|
||
def get_file(self, multihash, client_options=None, **kwargs): | ||
dst_path = kwargs.pop('filepath') | ||
response = self._request( | ||
command='download', | ||
hash=multihash, | ||
dest=dst_path | ||
) | ||
return [(dst_path, multihash, response['files'])] | ||
|
||
def pin_add(self, file_path, multihash): | ||
response = self._request( | ||
command='upload', | ||
files=[file_path], | ||
hash=multihash | ||
) | ||
return response['hash'] | ||
|
||
def pin_rm(self, multihash): | ||
response = self._request( | ||
command='cancel', | ||
hash=multihash | ||
) | ||
return response['hash'] | ||
|
||
def _request(self, **data): | ||
response = requests.post(url=self._url, | ||
headers=self._headers, | ||
data=json.dumps(data), | ||
timeout=self.timeout) | ||
|
||
response.raise_for_status() | ||
return json.loads(response.content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import atexit | ||
import logging | ||
import os | ||
import subprocess | ||
import time | ||
|
||
from requests import ConnectionError | ||
|
||
from golem.core.processmonitor import ProcessMonitor | ||
from golem.network.hyperdrive.client import HyperdriveClient | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class HyperdriveDaemonManager(object): | ||
|
||
_executable = 'hyperg' | ||
|
||
def __init__(self, datadir, **hyperdrive_config): | ||
super(HyperdriveDaemonManager, self).__init__() | ||
|
||
self._config = hyperdrive_config | ||
|
||
# monitor and restart if process dies | ||
self._monitor = ProcessMonitor() | ||
self._monitor.add_callbacks(self._start) | ||
|
||
# hyperdrive data directory | ||
self._dir = os.path.join(datadir, self._executable) | ||
if not os.path.exists(self._dir): | ||
os.makedirs(self._dir) | ||
|
||
atexit.register(self.stop) | ||
|
||
def start(self): | ||
self._monitor.start() | ||
self._start() | ||
|
||
def stop(self): | ||
self._monitor.exit() | ||
|
||
def _command(self): | ||
return [self._executable, '--db', self._dir] | ||
|
||
def _daemon_running(self): | ||
try: | ||
return HyperdriveClient(**self._config).id() | ||
except ConnectionError: | ||
return False | ||
|
||
def _start(self, *_): | ||
# do not supervise already running processes | ||
if self._daemon_running(): | ||
return | ||
|
||
process = subprocess.Popen(self._command()) | ||
while not self._daemon_running(): | ||
time.sleep(0.1) | ||
|
||
if process.poll() is None: | ||
self._monitor.add_child_processes(process) | ||
else: | ||
raise RuntimeError("Cannot start {}".format(self._executable)) |
Oops, something went wrong.