Пример #1
0
 def test_setRunTimeout (self):
     c = NDN ()
     c.run(0)
     
     def change_timeout():
         # print("Changing timeout!")
         c.setRunTimeout(1000)
     
     t = Timer(0.1, change_timeout)
     t.start()
     
     org_start = datetime.now()
     while True:
             self.assertLess ((datetime.now() - org_start).seconds, 3) # setRunTimeout() failed
     
     	start = datetime.now()
     	c.run(5)
     	diff = datetime.now() - start
     
     	if diff.seconds * 1000000 + diff.microseconds > 500000:
     		break
Пример #2
0
    def test_ndn_face_connect_disconnect(self):

        handle = _pyndn.create()

        self.assertRaises(
            _pyndn.NDNError, _pyndn.disconnect,
            handle)  # "Closing an unopened connection should fail"

        _pyndn.connect(handle)
        _pyndn.disconnect(handle)

        self.assertRaises(_pyndn.NDNError, _pyndn.disconnect,
                          handle)  # "Closing handle twice shouldn't work"

        del handle

        c = NDN()
        _pyndn.disconnect(c.ndn_data)
        del c
Пример #3
0
    def test_setRunTimeout(self):
        c = NDN()
        c.run(0)

        def change_timeout():
            # print("Changing timeout!")
            c.setRunTimeout(1000)

        t = Timer(0.1, change_timeout)
        t.start()

        org_start = datetime.now()
        while True:
            self.assertLess((datetime.now() - org_start).seconds,
                            3)  # setRunTimeout() failed

            start = datetime.now()
            c.run(5)
            diff = datetime.now() - start

            if diff.seconds * 1000000 + diff.microseconds > 500000:
                break
Пример #4
0
Файл: key.py Проект: MAHIS/PyNDN
locator1 = _pyndn.KeyLocator_to_ndn(name=ndn_name1)
print(locator1)

locator1_obj = _pyndn.KeyLocator_obj_from_ndn(locator1)
print(locator1_obj)
print(locator1_obj.keyName)

name2 = _pyndn.name_comps_from_ndn(locator1_obj.keyName.ndn_data)
print(name2)

for comp1, comp2 in zip(name1, name2):
	if comp1 != comp2:
		raise AssertionError("Got a different output: '%s' != '%s'" % (comp1, comp2))

key1 = NDN.getDefaultKey()

locator2 = _pyndn.KeyLocator_to_ndn(key=key1.ndn_data_public)
print(locator2)

locator2_obj = _pyndn.KeyLocator_obj_from_ndn(locator2)
key2 = locator2_obj.key
print(key2)

print(key1.ndn_data_public)
print(key2.ndn_data_public)

assert(key1.publicToDER() == key2.publicToDER())

del key2
key2 = _pyndn.Key_obj_from_ndn(key1.ndn_data_private)
Пример #5
0
root = os.path.join("tmp")
private_pem1 = os.path.join(root, 'private1.pem')
public_pem1 = os.path.join(root, 'public1.pem')
private_pem2 = os.path.join(root, 'private2.pem')
public_pem2 = os.path.join(root, 'public2.pem')


def rm_files(*list):
    for file in list:
        if os.path.exists(file):
            os.remove(file)


rm_files(private_pem1, public_pem1, private_pem2, public_pem2)

k = NDN.getDefaultKey()

k.privateToPEM(filename=private_pem1)
k.publicToPEM(filename=public_pem1)

k2 = Key()
k2.fromPEM(filename=private_pem1)

k2.privateToPEM(filename=private_pem2)
k2.publicToPEM(filename=public_pem2)

assert (filecmp.cmp(private_pem1, private_pem2))
assert (filecmp.cmp(public_pem1, public_pem2))
print(b64encode(k.publicKeyID))
print(b64encode(k2.publicKeyID))
assert (k.publicKeyID == k2.publicKeyID)
Пример #6
0
import os, filecmp
from base64 import b64encode, b64decode
from pyndn import Key, _pyndn, NDN

k = NDN.getDefaultKey()

private1_der = k.privateToDER()
public1_der = k.publicToDER()

k2 = Key()
k2.fromDER(private=private1_der)

private2_der = k2.privateToDER()
public2_der = k2.publicToDER()

assert(private1_der == private2_der)
assert(public1_der == public2_der)
assert(k.publicKeyID == k2.publicKeyID)

del(k2)

k2 = Key()
k2.fromDER(public=public1_der)

try:
	private2_der = k2.privateToDER()
except:
	pass
else:
	raise AssertionError("This should fail - this is not a private key")
import pyndn
from pyndn import NDN, Name, Interest, ContentObject, SignedInfo, Key, KeyLocator, Closure
#from threading import Timer

k = NDN.getDefaultKey()
kl = KeyLocator(k)

n = Name("/forty/two")


class SenderClosure(Closure):
    def upcall(self, kind, upcallInfo):
        global sender_handle, n, k, kl

        print("Sender closure:")
        print(upcallInfo)

        co = ContentObject()
        co.name = Name(n)
        co.content = "Frou"

        si = SignedInfo()
        si.publisherPublicKeyDigest = k.publicKeyID
        si.type = pyndn.CONTENT_DATA
        si.freshnessSeconds = 5
        si.keyLocator = kl

        co.signedInfo = si

        co.sign(k)
        r = sender_handle.put(co)
Пример #8
0
locator1 = _pyndn.KeyLocator_to_ndn(name=ndn_name1)
print(locator1)

locator1_obj = _pyndn.KeyLocator_obj_from_ndn(locator1)
print(locator1_obj)
print(locator1_obj.keyName)

name2 = _pyndn.name_comps_from_ndn(locator1_obj.keyName.ndn_data)
print(name2)

for comp1, comp2 in zip(name1, name2):
    if comp1 != comp2:
        raise AssertionError("Got a different output: '%s' != '%s'" %
                             (comp1, comp2))

key1 = NDN.getDefaultKey()

locator2 = _pyndn.KeyLocator_to_ndn(key=key1.ndn_data_public)
print(locator2)

locator2_obj = _pyndn.KeyLocator_obj_from_ndn(locator2)
key2 = locator2_obj.key
print(key2)

print(key1.ndn_data_public)
print(key2.ndn_data_public)

assert (key1.publicToDER() == key2.publicToDER())

del key2
key2 = _pyndn.Key_obj_from_ndn(key1.ndn_data_private)
Пример #9
0
		si.finalBlockID = last_segment
		si.publisherPublicKeyDigest = key.publicKeyID
		si.keyLocator = Key.KeyLocator(key)

		# ContentObject
		co = ContentObject.ContentObject()
		co.content = content
		co.name = co_name
		co.signedInfo = si

		co.sign(key)
		return co

	name = Name.Name('/repo/upload/test')
	name_v = Name.Name(name)
	name_v.appendVersion()

	handle = NDN.NDN()
	key = handle.getDefaultKey()
	last_seg = segment(9)

	content = []
	for i in range(10):
		name_s = Name.Name(name_v)
		name_s += segment(i)
		co = publish(key, name_s, last_seg, "Segment: %d\n" % i)
		content.append(co)

	upload = RepoUpload(handle, name_v, content)
	upload.start()
Пример #10
0
from pyndn import NDN, Name

c = NDN()
print(c)

n = Name()
print(n)

n = Name("ndn:/ndnx/ping")
print(n)

co = c.get(n)
print(co)

#this shouldn't cause segfault
print(n)

n = Name("ndn:/ndnx/some_nonexisting_name")
co = c.get(n, None, 100)

#this shouldn't cause segfault!
print(co)
Пример #11
0
from pyndn import NDN, _pyndn
from threading import Timer
from datetime import datetime

handle = _pyndn.create()

try:
    _pyndn.run(handle, 100)
except _pyndn.NDNError:
    pass
else:
    raise AssertionError("ndn_run() should fail when not connected")

del handle

c = NDN()
c.run(0)


def change_timeout():
    print("Changing timeout!")
    c.setRunTimeout(1000)


t = Timer(0.1, change_timeout)
t.start()

org_start = datetime.now()
while True:
    if (datetime.now() - org_start).seconds > 3:
        raise AssertionError("setRunTimeout() failed")
Пример #12
0
from pyndn import NDN, Name, Interest, Closure
from time import sleep

worked = False

class MyClosure(Closure):
	def upcall(self, kind, upcallInfo):
		global worked

		print("Got response")
		print(kind)
		print(upcallInfo)
		worked = True

n = Name("ndn:/ndnx/ping")

i = Interest()
closure = MyClosure()

c = NDN()
res = c.expressInterest(n, closure, i)
print(res)

#causes crashes
c.run(10)
print("Ha!")
assert(worked)
Пример #13
0
import pyndn
from pyndn import NDN, Name, Interest, ContentObject, SignedInfo, Key, KeyLocator, Closure
#from threading import Timer

k = NDN.getDefaultKey()
kl = KeyLocator(k)

n = Name("/forty/two")

class SenderClosure(Closure):
	def upcall(self, kind, upcallInfo):
		global sender_handle, n, k, kl

		print("Sender closure:")
		print(upcallInfo)

		co = ContentObject()
		co.name = Name(n)
		co.content = "Frou"

		si = SignedInfo()
		si.publisherPublicKeyDigest = k.publicKeyID
		si.type = pyndn.CONTENT_DATA
		si.freshnessSeconds = 5
		si.keyLocator = kl

		co.signedInfo = si

		co.sign(k)
		r = sender_handle.put(co)
		print("put(co) = ", r)