Exemplo n.º 1
0
	def unbind(self, ownerId, databaseId, nodeId, pointId):
		#trace("Meta.unbind")
		#TODO does this update some persistent record of local follows?
		#i.e. to allow them to be restored on reboot?
		####POSSIBLY DANGEROUS meta.addr.nodeId USAGE???
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, pointId, databaseId=self.databaseId)
		dst = StrAddress(ownerId, nodeId, pointId, databaseId=databaseId)
		self.link.write("meta.unbind.req " + str(src) + " " + str(dst))
Exemplo n.º 2
0
	def signup(self, ownerName, databaseId):
		"""signs up a new owner to the space"""
		self.addr.ownerId = self.idb.createOwner(ownerName)
		src = StrAddress(self.addr.ownerId, databaseId=databaseId)
		dst = StrAddress.EMPTY
		self.link.write("meta.signup.req " + str(src) + " " + str(dst) + " " + ownerName)
		return self.addr.ownerId
Exemplo n.º 3
0
	def login(self, ownerName, databaseId):
		ownerId = self.idb.getOwnerId(ownerName)
		self.addr = StrAddress(ownerId, databaseId=databaseId)
		src = self.addr
		dst = StrAddress.EMPTY
		self.link.write("meta.login.req " + str(src) + " " + str(dst) + " " + ownerName)
		return self.addr.ownerId
Exemplo n.º 4
0
	def createPoint(self, pointType, pointName):
		#trace("Meta.createPoint:" + str(pointType) + " " + str(pointName))

		####POSSIBLY DANGEROUS meta.addr.nodeId USAGE???
		pointId = self.idb.createPoint(self.addr.ownerId, self.addr.nodeId, pointType, pointName)
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, pointId, databaseId=self.databaseId)
		dst = StrAddress.EMPTY
		self.link.write(
			"meta.createpoint.req " + str(src) + " " + str(dst) + " " + str(pointType) + " " + str(pointName))
		return pointId
Exemplo n.º 5
0
	def approvedBind(self, bindType, ownerId, databaseId, nodeId, pointId):
		#trace("Meta.approvedBind:" + str(ownerId) + " " + str(nodeId) + " " + str(pointId))
		####POSSIBLY DANGEROUS meta.addr.nodeId USAGE???
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, databaseId=self.databaseId)
		dst = StrAddress(ownerId, nodeId, pointId, databaseId=databaseId)
		# The other end of the binding makes the decision to allow/deny the bind.
		self.link.write("meta.bind.req " + str(src) + " " + str(dst) + " " + str(bindType))

		#TODO inner class, should this be in VirtualSpace??
		class Binding():
			def __init__(self, meta, bindType, ownerId, nodeId, pointId):
				self.bindType = bindType
				self.ownerId = ownerId
				self.nodeId = nodeId
				self.pointId = pointId
				self.meta = meta

			def unbind(self):
				self.meta.unbind(self.ownerId, self.nodeId, self.pointId)

		return Binding(self, bindType, ownerId, nodeId, pointId)
Exemplo n.º 6
0
	def __init__(self, link, databaseId, dbPath=None):
		self.link = link
		self.poller = ConnectionPoller(link)

		self.databaseId = databaseId
		self.addr = StrAddress(databaseId=databaseId)

		self.idb = IdDatabase(dbPath)
		self.idb.open()

		anyAddr = StrAddress.EMPTY

		self.poller.registerListener(None, anyAddr, anyAddr, self.handleMeta)
Exemplo n.º 7
0
	def assumedBind(self, bindType, ownerId, databaseId, nodeId, pointId):
		#trace("Meta.assumedBind: (" + str(ownerId) + " " + str(nodeId) + " " + str(pointId) + ")")
		####POSSIBLY DANGEROUS meta.addr.nodeId USAGE???
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, databaseId=self.databaseId)
		dst = StrAddress(ownerId, nodeId, pointId, databaseId=databaseId)
		#trace("assumedBind: src=" + str(src) + " dst=" + str(dst))
		self.link.write("meta.bind.ind " + str(src) + " " + str(dst) + " " + str(bindType))
		# This is an assumed bind, so we write it directly to our database
		self.idb.bind(bindType, src.ownerId, src.databaseId, src.nodeId, src.pointId,
					  dst.ownerId, dst.databaseId, dst.nodeId, dst.pointId)

		#TODO inner class, should this be in VirtualSpace??
		class Binding():
			def __init__(self, meta, bindType, ownerId, nodeId, pointId):
				self.bindType = bindType
				self.ownerId = ownerId
				self.nodeId = nodeId
				self.pointId = pointId
				self.meta = meta

			def unbind(self):
				self.meta.unbind(self.ownerId, self.nodeId, self.pointId)

		return Binding(self, bindType, ownerId, nodeId, pointId)
Exemplo n.º 8
0
	def waitBind(self, bindType, ownerId, databaseId, nodeId, pointId):
		#trace("waiting for bind to succeed")
		src = self.addr
		dst = StrAddress(ownerId, nodeId, pointId, databaseId=databaseId)

		if bindType=="ONE_TO_MANY": # addresses must be swapped for follow
			src, dst = dst, src

		while True:
			self.loop() # allow message processing
			b = self.idb.isBound(src, dst, bindType)
			if b:
				return # bound
			#trace("WAIT for bind bindType:" + str(bindType) + " src:" + str(src) + " dst:" + str(dst))
			time.sleep(1)
Exemplo n.º 9
0
	def createPointRec(self, ownerId, nodeId, pointType, pointName, pointId, databaseId, isLocal=False):
		"""Low level POINT record creation"""
		rec = {
			"type":      'POINT',
			"ownerId":   ownerId,
			"databaseId":databaseId,
			"nodeId":    nodeId,
			'name':      pointName,
			"pointType": pointType
		}
		if isLocal:
			if pointId != None:
				rec["id"] = pointId

		newPointId = self.db.write(rec, morekeys=["pointId"])
		if isLocal:
			self.writeId(StrAddress(ownerId, nodeId, newPointId, databaseId=self.databaseId), "POINT", pointName)
		return newPointId
Exemplo n.º 10
0
	def createOwnerRec(self, ownerName, databaseId, ownerId=None, isLocal=False):
		"""Create a record in db for an owner"""
		#This might be a locally created owner, or an address reference to an owner

		rec = {
			"type":       "OWNER",
			"name":       ownerName,
			"databaseId": databaseId
		}

		if isLocal:
			if ownerId != None:
				rec["id"] = ownerId

		newOwnerId = self.db.write(rec, morekeys=["ownerId"])
		if isLocal:
			# Only locally created ownerId's get written to our id cache
			self.writeId(StrAddress(newOwnerId), "OWNER", ownerName)
		return newOwnerId
Exemplo n.º 11
0
	def createNodeRec(self, ownerId, nodeId, databaseId, nodeName, isLocal=False):
		"""low-level create a brand new nodeId, fail if it already exists"""

		rec = {
			"type":      "NODE",
			"ownerId":    ownerId,
			"name":       nodeName,
			"databaseId": databaseId
		}
		if isLocal:
			if nodeId != None: # forcing a nodeId
				rec["id"] = nodeId
			newNodeId = self.db.write(rec, morekeys=["nodeId"])
			self.writeId(StrAddress(ownerId, newNodeId, databaseId=self.databaseId), "NODE", nodeName)

		else: # remote
			if nodeId == None:
				raise ValueError("Remote Node requires a nodeId")
			rec["nodeId"] = nodeId
			newNodeId = self.db.write(rec)

		return newNodeId
Exemplo n.º 12
0
	def remove(self, pointId):
		####POSSIBLY DANGEROUS meta.addr.nodeId USAGE???
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, pointId, databaseId=self.databaseId)
		dst = StrAddress.EMPTY
		self.link.write("meta.remove.req " + str(src) + " " + str(dst))
		self.idb.deletePoint(self.addr.ownerId, self.addr.nodeId, pointId)
Exemplo n.º 13
0
	def hide(self, pointId):  #TODO unadvertise
		####POSSIBLY DANGEROUS meta.addr.nodeId USAGE???
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, pointId, databaseId=self.databaseId)
		dst = StrAddress.EMPTY
		self.idb.changePointState(self.addr.ownerId, self.addr.nodeId, pointId, "HIDDEN")
		self.link.write("meta.hide.req " + str(src) + " " + str(dst))
Exemplo n.º 14
0
	def __init__(self, ownerId, databaseId, nodeId, link):
		self.link = link
		self.poller = ConnectionPoller(link)
		self.addr = StrAddress(ownerId, nodeId, databaseId=databaseId)
		self.databaseId = databaseId
Exemplo n.º 15
0
	def setNodeStateForId(self, ownerId, nodeId, state):
		#trace("Meta.setNodeState:" + str(ownerId) + " " + str(nodeId) + " " + str(state))
		self.idb.changeNodeState(ownerId, nodeId, state)
		src = StrAddress(ownerId, nodeId, databaseId=self.databaseId)
		dst = StrAddress.EMPTY
		self.link.write("meta.state.ind " + str(src) + " " + str(dst) + " " + state)
Exemplo n.º 16
0
	def sendto(self, ownerId, databaseId, nodeId, pointId, data=None, fromPointId=None):
		#trace("Data.sendto: o=" + str(ownerId) + " d=" + str(databaseId) + " n=" + str(nodeId) + " p=" + str(pointId))
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, fromPointId, databaseId=self.databaseId)
		dest = StrAddress(ownerId, nodeId, pointId, databaseId=databaseId)
		self.link.write("data.payload " + str(src) + " " + str(dest) + " " + str(data))
Exemplo n.º 17
0
	def send(self, data=None, fromPointId=None):
		#trace("Data.send: fromPointId=" + str(fromPointId))
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, fromPointId, databaseId=self.databaseId)
		dst = StrAddress()
		#trace("Data.send:" + str(src) + " " + str(dst))
		self.link.write("data.payload " + str(src) + " " + str(dst) + " " + str(data))
Exemplo n.º 18
0
	def iAmPoint(self, ownerId, databaseId, nodeId, pointId, pointName, dst):
		#trace("iAmPoint:" + str(ownerId) + " " + str(databaseId) + " " + str(nodeId) + " " + str(pointId) + " " + str(pointName) + " => " + str(dst))
		src = StrAddress(ownerId, nodeId, pointId, databaseId=databaseId)
		self.link.write("meta.whois.rsp " + str(src) + " " + str(dst) + " " + pointName)
Exemplo n.º 19
0
	def whoisPoint(self, ownerId, databaseId, nodeId, pointName):
		#trace("whoisPoint:" + str(ownerId) + " " + str(nodeId) + " " + str(pointName))
		####POSSIBLY DANGEROUS meta.addr.nodeId USAGE???
		src = StrAddress(self.addr.ownerId, self.addr.nodeId, databaseId=self.databaseId)
		dst = StrAddress(ownerId, nodeId, databaseId=databaseId)
		self.link.write("meta.whois.req " + str(src) + " " + str(dst) + " " + str(pointName))
Exemplo n.º 20
0
	def whoisOwner(self, ownerName):
		#trace("whoisOwner:" + str(ownerName))
		src = StrAddress(self.addr.ownerId, databaseId=self.databaseId)
		dst = StrAddress.EMPTY
		self.link.write("meta.whois.req " + str(src) + " " + str(dst) + " " + str(ownerName))