예제 #1
0
    def __init__(self):
        self.n = Node(cert='serverside.pem')
        self.n.listen(port=10002)
        ref = self.n.register(self)
        print 'Master at', self.n.refurl(ref)

        self.slaves = {}
        later(5.0, self.process)
예제 #2
0
파일: fserver.py 프로젝트: rep/pwrfs
def main():
	global SDIR
	SDIR = sys.argv[1]
	secret = sys.argv[2]

	if not (os.path.exists(SDIR) and os.path.isdir(SDIR)):
		os.mkdir(SDIR)

	n = Node(cert=None)
	n.listen(port=PORT)
	gs = Fileserver()
	ref = n.register(gs, cap=secret)
	logging.info('gs at {0}'.format(n.refurl(ref)))

	loop()
	return 0
예제 #3
0
class pwrfscli(object):
    def __init__(self, mountdir):
        self.mountdir = mountdir
        self.n = Node(cert=None)
        self.fuse = None
        later(0.0, self.connect)

    def connect(self):
        self.rc = self.n.connect(HOST, PORT)
        self.rc._on('ready', self.server_ready)
        self.rc._on('close', self.server_closed)

    def server_ready(self):
        print 'server ready.'
        if not self.fuse: self.fuse = pwrfuse(self.mountdir, self)

    def server_closed(self, e):
        print 'server closed.', e
        later(5.0, self.connect)

    def call(self, *args, **kwargs):
        try:
            return self.rc.call(REF, *args, **kwargs)
        except EVException:
            p = Promise()
            p._smash(EVException('Server currently unavailable.'))
            return p

    def _unmount(self):
        if self.fuse: self.fuse._unmount()
예제 #4
0
파일: pwrmount.py 프로젝트: rep/pwrfs
class pwrfscli(object):
	def __init__(self, mountdir):
		self.mountdir = mountdir
		self.n = Node(cert=None)
		self.fuse = None
		later(0.0, self.connect)

	def connect(self):
		self.rc = self.n.connect(HOST, PORT)
		self.rc._on('ready', self.server_ready)
		self.rc._on('close', self.server_closed)

	def server_ready(self):
		print 'server ready.'
		if not self.fuse: self.fuse = pwrfuse(self.mountdir, self)

	def server_closed(self, e):
		print 'server closed.', e
		later(5.0, self.connect)

	def call(self, *args, **kwargs):
		try: return self.rc.call(REF, *args, **kwargs)
		except EVException:
			p = Promise()
			p._smash(EVException('Server currently unavailable.'))
			return p

	def _unmount(self):
		if self.fuse: self.fuse._unmount()
예제 #5
0
def main():
    n = Node(cert='serverside.pem')
    im = Instamaster()
    ref = n.register(im, 'im')
    n._on('connection', im.on_new_conn)
    n.listen(port=20001)
    print 'Instamaster at', n.refurl(ref)

    loop()

    return 0
예제 #6
0
class Master(object):
    def __init__(self):
        self.n = Node(cert='serverside.pem')
        self.n.listen(port=10002)
        ref = self.n.register(self)
        print 'Master at', self.n.refurl(ref)

        self.slaves = {}
        later(5.0, self.process)

    def process(self):
        slaves = self.slaves.values()
        if not slaves:
            later(5.0, self.process)
            print 'process, but no slaves'
            return

        somerand = random.randint(10, 200)
        data = range(somerand * 720, (somerand + 1) * 720)

        pr = Processround(slaves, data, 'procfunc', sum)
        p = pr.run()
        p._except(self.roundfailed)
        p._when(self.roundresult, sum(data))

    def roundresult(self, r, should):
        print 'roundresult, shouldbe:', r, should, r == should
        later(5.0, self.process)

    def roundfailed(self, e):
        print 'processround failed:', e
        later(5.0, self.process)

    @expose
    def addslave(self, slave, conn):
        self.slaves[conn] = slave

        def connclosed(reason):
            sl = self.slaves.pop(conn, None)
            print 'slave {0} gone, as conn {1} is closed.'.format(sl, conn)

        conn._on('close', connclosed)
        return True
예제 #7
0
파일: instashare.py 프로젝트: rep/pwrcall
def main(options, action, args):
	n = Node(cert=CERTPATH)

	if action == 'listen':
		ic = Instaclient(n)
		loop()
	elif action == 'send':
		targetcap, fp = args

		if not (os.path.exists(fp) and os.path.isfile(fp)):
			print fp, 'not a file'
			return 1

		im = n.establish(MASTERURL)

		def established(rim):
			p = rim.call('open', targetcap)

			def donecb(r):
				print 'done:', r
				n.shutdown()
				unloop()

			def prsink(r):
				print 'sink:' , r
				r.notify('init', os.path.basename(fp))
				fs = Filestreamer(open(fp, 'rb'), r, rim.conn)
				fs.p._when(donecb)
				fs.p._except(donecb)

			def prexcept(e):
				print 'Error:', e
				n.shutdown()
				unloop()

			p._when(prsink)
			p._except(prexcept)

		im._when(established)
		loop()

	return 0
예제 #8
0
파일: instashare.py 프로젝트: rep/pwrcall
def main(options, action, args):
    n = Node(cert=CERTPATH)

    if action == 'listen':
        ic = Instaclient(n)
        loop()
    elif action == 'send':
        targetcap, fp = args

        if not (os.path.exists(fp) and os.path.isfile(fp)):
            print fp, 'not a file'
            return 1

        im = n.establish(MASTERURL)

        def established(rim):
            p = rim.call('open', targetcap)

            def donecb(r):
                print 'done:', r
                n.shutdown()
                unloop()

            def prsink(r):
                print 'sink:', r
                r.notify('init', os.path.basename(fp))
                fs = Filestreamer(open(fp, 'rb'), r, rim.conn)
                fs.p._when(donecb)
                fs.p._except(donecb)

            def prexcept(e):
                print 'Error:', e
                n.shutdown()
                unloop()

            p._when(prsink)
            p._except(prexcept)

        im._when(established)
        loop()

    return 0
예제 #9
0
파일: instamaster.py 프로젝트: rep/pwrcall
def main():
	n = Node(cert='serverside.pem')
	im = Instamaster()
	ref = n.register(im, 'im')
	n._on('connection', im.on_new_conn)
	n.listen(port=20001)
	print 'Instamaster at', n.refurl(ref)

	loop()

	return 0
예제 #10
0
class ClientClass(object):
	def __init__(self):
		self.n = Node(cert=CERT)
		self.rpcconn = None
		self.connect()
		
	def connect(self, reason=''):
		#self.rc = self.n.connect(HOST, PORT)
		conn_promise = self.n.establish(PURL)
		conn_promise._when(self.established)
		conn_promise._except(self.notestablished)

	def established(self, rpcconn):
		def delay(reason): later(3.0, self.connect)
		rpcconn.conn._on('close', delay)

		print 'now we are connected!', rpcconn
		self.rpcconn = rpcconn

	def notestablished(self, error):
		later(3.0, self.connect)
예제 #11
0
파일: fserver.py 프로젝트: rep/pwrfs
def main():
    global SDIR
    SDIR = sys.argv[1]
    secret = sys.argv[2]

    if not (os.path.exists(SDIR) and os.path.isdir(SDIR)):
        os.mkdir(SDIR)

    n = Node(cert=None)
    n.listen(port=PORT)
    gs = Fileserver()
    ref = n.register(gs, cap=secret)
    logging.info('gs at {0}'.format(n.refurl(ref)))

    loop()
    return 0
예제 #12
0
class ClientClass(object):
    def __init__(self):
        self.n = Node(cert=CERT)
        self.rpcconn = None
        self.connect()

    def connect(self, reason=''):
        #self.rc = self.n.connect(HOST, PORT)
        conn_promise = self.n.establish(PURL)
        conn_promise._when(self.established)
        conn_promise._except(self.notestablished)

    def established(self, rpcconn):
        def delay(reason):
            later(3.0, self.connect)

        rpcconn.conn._on('close', delay)

        print 'now we are connected!', rpcconn
        self.rpcconn = rpcconn

    def notestablished(self, error):
        later(3.0, self.connect)
예제 #13
0
파일: giftcli.py 프로젝트: rep/pwrcall
import sys
from pwrcall import loop, unloop, Node, expose, util

n = Node(cert='clientside.pem')
math = n.establish(sys.argv[1])
giftr = n.establish(sys.argv[2])
#math2 = n.connect('127.0.0.1', 10000).rootobj().call('get', sys.argv[1].split('/')[-1])

def printexception(r, msg):
	print 'exc', msg, ':', r
	n.shutdown()
	unloop()

def printresult(result):
	print 'printresult:', result

def revokedone(res):
	print 'revokedone', res

def doneusing(result, m, ccapp):
	print 'giftreceiver is done using object:', result
	fp, hints, cap = util.parse_url(ccapp)
	print 'asking the owner to revoke the cap...'
	revokep = m.conn.call('$node', 'revoke', cap)
	revokep._when(revokedone)
	revokep._except(printexception, 'revoking')

def gotclonecap(ccapp, m):
	print 'got clone cap:', ccapp
	rp = giftr.call('donate', ccapp)
	rp._when(doneusing, m, ccapp)
예제 #14
0
파일: cli.py 프로젝트: rep/pwrcall
import sys
from pwrcall import loop, unloop, Node, expose
from evnet import later

n = Node(cert='clientside.pem')
math = n.establish(sys.argv[1])

def printexception(r):
	print 'exc:', r
	n.shutdown()
	unloop()

def printresult(result):
	print 'printresult:', result

def close(r=None):
	n.shutdown()
	unloop()

math._except(printexception)
p = math.call('new', './module/', 'test')
p._when(printresult)

ap = p.call('add', 4, 5)
ap._when(printresult)

lp = math.call('list')
lp._when(printresult)

later(5.0,close)
예제 #15
0
파일: giftreceiver.py 프로젝트: rep/pwrcall
import logging
logging.basicConfig(level=logging.DEBUG)

from pwrcall import loop, unloop, Node, expose, Promise
from evnet import later

n = Node(cert='serverside2.pem')

class Giftreceiver(object):
	def __init__(self):
		self.donaterunpromise = Promise()
		self.obj = None

	@expose
	def donate(self, url):
		#print obj, obj.conn, obj.functions
		print url
		self.obj = n.establish(url)
		r = self.obj.call('add', 10, 31)
		r._when(self.done)
		return self.donaterunpromise

	def done(self, r):
		print 'done using the object, result:', r
		self.donaterunpromise._resolve('Thanks, i am done!.')
		later(3, self.retry)

	def works(self, r):
		print 'reusing worked, result:', r
		later(3, self.retry)
예제 #16
0
	def __init__(self):
		self.n = Node(cert=CERT)
		self.rpcconn = None
		self.connect()
예제 #17
0
 def __init__(self):
     self.n = Node(cert=CERT)
     self.rpcconn = None
     self.connect()
예제 #18
0
파일: server.py 프로젝트: rep/pwrcall
import logging
logging.basicConfig(level=logging.DEBUG)

from pwrcall import loop, unloop, Node, expose
import pyev
import evnet


class Math(object):
    @expose
    def add(self, a, b):
        return a + b

    @expose
    def mul(self, a, b):
        return a * b


n = Node(cert='cert.pem')
ref = n.register_object(Math())
n.listen(port=10000)
print 'math obj ready at', n.refurl(ref)

loop()
예제 #19
0
파일: server.py 프로젝트: rep/pwrcall
import logging
logging.basicConfig(level=logging.DEBUG)

from pwrcall import loop, unloop, Node, expose
import pyev
import evnet

class Math(object):
	@expose
	def add(self, a, b):
		return a+b

	@expose
	def mul(self, a, b):
		return a*b

n = Node(cert='cert.pem')
ref = n.register_object(Math())
n.listen(port=10000)
print 'math obj ready at', n.refurl(ref)

loop()

예제 #20
0
파일: pwr.py 프로젝트: rep/pwrcall
	def list(self):
		return dict([(k, [v.fpath, v.modname, str(v.ref)]) for k,v in self.apps.items()])

	@expose
	def get(self, appid):
		a = self.apps.get(appid, None)
		if a == None:
			raise NodeException('Nonexisting app.')
		return a.ref

	@expose
	def restart(self, appid):
		a = self.apps.get(appid, None)
		if a == None:
			raise NodeException('Nonexisting app.')
		nmod, nref = load_pwrobj(a.fpath, a.modname)
		a.modref = nmod
		a.ref = nref
		return nref
		

if __name__ == '__main__':
	n = Node(cert=CERT)
	n.listen(port=PORT)
	appsrvobj = Appserver()
	ref = n.register(appsrvobj)
	print 'appserver at', n.refurl(ref)

	loop()

예제 #21
0
파일: client.py 프로젝트: rep/pwrcall
        n.shutdown()
        unloop()

    c += 1
    ctime = time.time()

    if c % 1000 == 0:
        print int(ctime * 1000), c

    if ctime - starttime < 60.0:
        startcall()
    else:
        print int(ctime * 1000), c
        n.shutdown()
        unloop()


n = Node(cert='cert2.pem')
math = n.establish(sys.argv[1])
math._except(printexception)

c = 0
starttime = time.time()
ctime = time.time()
print int(ctime * 1000), c

for i in range(10):
    startcall()

loop()
예제 #22
0
import sys
import logging
logging.basicConfig(level=logging.DEBUG)

from pwrcall import loop, unloop, Node, expose


class Math(object):
    @expose
    def add(self, a, b):
        return a + b


n = Node(cert='serverside.pem')
m = Math()
if len(sys.argv) > 1:
    ref = n.register(m, cap=sys.argv[1])
else:
    ref = n.register(m)
n.listen(port=10000)
print 'math obj ready at', n.refurl(ref)

loop()
예제 #23
0
 def __init__(self, mountdir):
     self.mountdir = mountdir
     self.n = Node(cert=None)
     self.fuse = None
     later(0.0, self.connect)
예제 #24
0
import sys
from IPython.Shell import IPShellEmbed
from evnet import pyevThread
from pwrcall import Node, expose, loop, unloop
from pwrcall.util import NodeException, parse_url

CERT = 'clientside.pem'
t = pyevThread()
t.start()
n = Node(cert=CERT)
ipshell = IPShellEmbed()


def establish(pwrurl):
    return t.blockingCall(n.establish, pwrurl)


def pwrcall(obj, fn, *args):
    return t.blockingCall(obj.call, fn, *args)


if __name__ == '__main__':
    ipshell.set_banner('''pwrcall Interactive Shell
-------------------------
starts up a evnet loop and pwrcall Node
use the Node through the t.blockingCall function''')
    ipshell.set_exit_msg('Exit.')
    ipshell()
    sys.exit(0)
예제 #25
0
파일: mathcli.py 프로젝트: rep/pwrcall
import sys
from pwrcall import loop, unloop, Node, expose
import logging
logging.basicConfig(level=logging.DEBUG)

n = Node(cert='clientside.pem')
math = n.establish(sys.argv[1])
#math2 = n.connect('127.0.0.1', 10000).rootobj().call('get', sys.argv[1].split('/')[-1])

def printexception(r):
	print 'exc:', r
	n.shutdown()
	unloop()

math._except(printexception)
p = math.call('add', 11, 17)

def printresult(result):
	print 'printresult:', result
	n.shutdown()
	unloop()

p._when(printresult)

loop()

예제 #26
0
파일: giftreceiver.py 프로젝트: rep/pwrcall
import logging

logging.basicConfig(level=logging.DEBUG)

from pwrcall import loop, unloop, Node, expose, Promise
from evnet import later

n = Node(cert="serverside2.pem")


class Giftreceiver(object):
    def __init__(self):
        self.donaterunpromise = Promise()
        self.obj = None

    @expose
    def donate(self, url):
        # print obj, obj.conn, obj.functions
        print url
        self.obj = n.establish(url)
        r = self.obj.call("add", 10, 31)
        r._when(self.done)
        return self.donaterunpromise

    def done(self, r):
        print "done using the object, result:", r
        self.donaterunpromise._resolve("Thanks, i am done!.")
        later(3, self.retry)

    def works(self, r):
        print "reusing worked, result:", r
예제 #27
0
파일: pwrmount.py 프로젝트: rep/pwrfs
	def __init__(self, mountdir):
		self.mountdir = mountdir
		self.n = Node(cert=None)
		self.fuse = None
		later(0.0, self.connect)
예제 #28
0
    def list(self):
        return dict([(k, [v.fpath, v.modname, str(v.ref)])
                     for k, v in self.apps.items()])

    @expose
    def get(self, appid):
        a = self.apps.get(appid, None)
        if a == None:
            raise NodeException('Nonexisting app.')
        return a.ref

    @expose
    def restart(self, appid):
        a = self.apps.get(appid, None)
        if a == None:
            raise NodeException('Nonexisting app.')
        nmod, nref = load_pwrobj(a.fpath, a.modname)
        a.modref = nmod
        a.ref = nref
        return nref


if __name__ == '__main__':
    n = Node(cert=CERT)
    n.listen(port=PORT)
    appsrvobj = Appserver()
    ref = n.register(appsrvobj)
    print 'appserver at', n.refurl(ref)

    loop()
예제 #29
0
파일: mathsrv.py 프로젝트: rep/pwrcall
import sys
import logging
logging.basicConfig(level=logging.DEBUG)

from pwrcall import loop, unloop, Node, expose

class Math(object):
	@expose
	def add(self, a, b):
		return a+b

n = Node(cert='serverside.pem')
m = Math()
if len(sys.argv) > 1:
	ref = n.register(m, cap=sys.argv[1])
else:
	ref = n.register(m)
n.listen(port=10000)
print 'math obj ready at', n.refurl(ref)

loop()