示例#1
0

	def startChannelConversation(self, localID, channelIndex):
		inputMessage = messages.ChannelMessage(
			ID=localID,
			channelIndex=channelIndex,
			message=None #None = start of conversation
			)

		return self.continueChannelConversation(inputMessage)


	def continueChannelConversation(self, msg):
		outputMessage = self.channels[msg.channelIndex].handleMessage(msg.message)

		if outputMessage is None: #None = end of conversation
			return []

		return \
			[
			messages.OutboundMessage(localID=msg.ID, message=messages.ChannelMessage(
				ID=self.remoteID,
				channelIndex=msg.channelIndex,
				message=outputMessage
				))
			]


serializable.registerClass(Link)

示例#2
0

class Connect(serializable.Serializable):
    """
	This is a base class for messages that indicate a connection ID
	(Link and Pay).
	"""

    serializableAttributes = {"ID": "", "dice": 0}


class Pay(Connect):
    pass


serializable.registerClass(Pay)


class ConnectLink(Connect):
    serializableAttributes = {"ID": "", "dice": 0, "callbackHost": None, "callbackPort": None, "callbackID": None}


serializable.registerClass(ConnectLink)


class Confirmation(serializable.Serializable):
    serializableAttributes = {"localID": "", "index": 0}


serializable.registerClass(Confirmation)
示例#3
0
			return self.payerLink
		elif linkID in self.payeeLinks.keys():
			return self.payeeLinks[linkID]
		elif linkID in self.links.keys():
			return self.links[linkID]

		raise LinkNotFound("Link ID %s not found" % repr(linkID))


	def msg_passToPayee(self, msg):
		payee = self.payeeLinks[msg.ID]
		return payee.handleMessage(msg)


	def msg_passToPayer(self, msg):
		if self.payerLink is None:
			raise Exception("Received message for payer, but there is no payer")
		return self.payerLink.handleMessage(msg)


	def msg_passToConnection(self, msg):
		return self.connections[msg.localID].handleMessage(msg)


	def msg_passToLink(self, msg):
		return self.links[msg.ID].handleMessage(msg)


serializable.registerClass(NodeState)

#    with the OpenSSL library (or a modified version of that library),
#    containing parts covered by the terms of the OpenSSL License and the SSLeay
#    License, the licensors of this Program grant you additional permission to
#    convey the resulting work. Corresponding Source for a non-source form of
#    such a combination shall include the source code for the parts of the
#    OpenSSL library used as well as that of the covered work.

import messages

import serializable



class PersistentConnectionMessage(serializable.Serializable):
	serializableAttributes = {'message': None, 'index': 0}
serializable.registerClass(PersistentConnectionMessage)



class PersistentConnection(serializable.Serializable):
	serializableAttributes = \
	{
		'host'             : None,
		'port'             : None,
		'connectMessage'   : None,
		'messages'         : [],
		'lastIndex'        : -1,
		'notYetTransmitted': 0,
		'closing'          : False
	}
示例#5
0
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Amiko Pay is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Amiko Pay. If not, see <http://www.gnu.org/licenses/>.
#
#    Additional permission under GNU GPL version 3 section 7
#
#    If you modify this Program, or any covered work, by linking or combining it
#    with the OpenSSL library (or a modified version of that library),
#    containing parts covered by the terms of the OpenSSL License and the SSLeay
#    License, the licensors of this Program grant you additional permission to
#    convey the resulting work. Corresponding Source for a non-source form of
#    such a combination shall include the source code for the parts of the
#    OpenSSL library used as well as that of the covered work.

import serializable



class MeetingPoint(serializable.Serializable):
	serializableAttributes = {'transactions':{}}
serializable.registerClass(MeetingPoint)

示例#6
0
	def commitOutgoing(self, msg):
		if self.state != self.states.locked:
			raise Exception(
				"commitOutgoing should not be called in state %s" % \
					self.state
				)
		self.state = self.states.receivedCommit
		self.token = msg.token #TODO: maybe check?

		return \
		[
		messages.TimeoutMessage(timestamp=time.time()+1.0, message=\
			self.getTimeoutMessage()  #Add time-out to go to commit
		)
		]


	def settleCommitIncoming(self, msg):
		#TODO: receive token, and check it!

		log.log("Payer: received settleCommit -> committed")
		self.state = self.states.committed
		self.__finished.set()

		return []


serializable.registerClass(PayerLink)

示例#7
0
#
#    You should have received a copy of the GNU General Public License
#    along with Amiko Pay. If not, see <http://www.gnu.org/licenses/>.
#
#    Additional permission under GNU GPL version 3 section 7
#
#    If you modify this Program, or any covered work, by linking or combining it
#    with the OpenSSL library (or a modified version of that library),
#    containing parts covered by the terms of the OpenSSL License and the SSLeay
#    License, the licensors of this Program grant you additional permission to
#    convey the resulting work. Corresponding Source for a non-source form of
#    such a combination shall include the source code for the parts of the
#    OpenSSL library used as well as that of the covered work.

import serializable


side_payer = 1
side_midpoint = 0
side_payee = -1


class Transaction(serializable.Serializable):
	serializableAttributes = \
	{
	'side':None, 'payeeID':None, 'payerID':None, 'remainingLinkIDs':[],
	'meetingPointID':None, 'amount':0, 'startTime':0, 'endTime':0
	}
serializable.registerClass(Transaction)