Skip to content

Commit

Permalink
fix a typo bug, correct some comments, and add some TODO comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LipuFei committed Mar 10, 2015
1 parent 51b653f commit 5b24637
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions community.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,17 @@ def create_community(cls, dispersy, my_member, *args, **kargs):

# ensure that undo_callback is available
if message.undo_callback:
# we do not support undo permissions for authorize, revoke, undo-own, undo-other,
# cancel-own, and cancel-other (yet)
# we do not support undo permissions for authorize, revoke, undo-own, and
# undo-other (yet)
if not message.name in message_names:
permission_triplets.append((my_member, message, u"undo"))

# TODO: This is a DUPLICATE of undo, add comments after we remove undo.
# TODO(lfei): remove undo_callback part after we have completely removed the undo message
# TODO(lfei): make sure the comments are correct
# ensure that cancel_callback is available
if message.cancel_callback:
if not message.name in message_names:
# we do not support cancel permissions for authorize, revoke, cancel-own, and cancel-other (yet)
if message.name not in message_names:
permission_triplets.append((my_member, message, u"cancel"))

# grant authorize, revoke, and undo permission for messages that use PublicResolution
Expand All @@ -165,15 +168,18 @@ def create_community(cls, dispersy, my_member, *args, **kargs):
elif isinstance(message.distribution, SyncDistribution) and isinstance(message.resolution, PublicResolution):
# ensure that undo_callback is available
if message.undo_callback:
# we do not support undo permissions for authorize, revoke, undo-own, undo-other,
# cancel-own, and cancel-other (yet)
# we do not support undo permissions for authorize, revoke, undo-own, and
# undo-other (yet)
if not message.name in message_names:
for allowed in (u"authorize", u"revoke", u"undo"):
permission_triplets.append((my_member, message, allowed))

# TODO: This is a DUPLICATE of undo, add comments after we remove undo.
if message.undo_callback:
if not message.name in message_names:
# TODO(lfei): remove undo_callback part after we have completely removed the undo message
# TODO(lfei): make sure the comments are correct
# ensure that cancel_callback is available
if message.cancel_callback:
# we do not support cancel permissions for authorize, revoke, cancel-own, and cancel-other (yet)
if message.name not in message_names:
for allowed in (u"authorize", u"revoke", u"cancel"):
if (my_member, message, allowed) not in permission_triplets:
permission_triplets.append((my_member, message, allowed))
Expand Down Expand Up @@ -3306,6 +3312,7 @@ def on_revoke(self, messages, initializing=False):
for meta, globaltime_range in changes.iteritems():
self._update_timerange(meta, globaltime_range[0], globaltime_range[1])

# TODO(lfei): make sure that the comments are correct
def create_cancel(self, message, sign_with_master=False, store=True, update=True, forward=True):
"""
Creates a cancel message to end the loop of undo messages.
Expand All @@ -3321,7 +3328,7 @@ def create_cancel(self, message, sign_with_master=False, store=True, update=True
assert isinstance(update, bool)
assert isinstance(forward, bool)
assert message.cancel_callback, "message does not allow cancel"
assert not message.name in (u"dispersy-cancel-own", u"dispersy-cancel-other",
assert message.name not in (u"dispersy-cancel-own", u"dispersy-cancel-other",
u"dispersy-undo-own", u"dispersy-undo-other",
u"dispersy-authorize", u"dispersy-revoke"),\
"Currently we do NOT support canceling any of these, as it has consequences for other messages"
Expand Down Expand Up @@ -3356,6 +3363,7 @@ def create_cancel(self, message, sign_with_master=False, store=True, update=True
self._dispersy.store_update_forward([msg], store, update, forward)
return msg

# TODO(lfei): make sure that the comments are correct
def check_cancel(self, messages):
# Note: previously all MESSAGES have been checked to ensure that the sequence numbers are
# correct. this check takes into account the messages in the batch. hence, if one of these
Expand Down Expand Up @@ -3395,6 +3403,7 @@ def check_cancel(self, messages):

yield message

# TODO(lfei): make sure that the comments are correct
def on_cancel(self, messages):
"""
Cancels a single message.
Expand Down Expand Up @@ -3456,7 +3465,6 @@ def on_cancel(self, messages):

# sort and get the latest one
all_item_list.sort()
self._logger.debug("!!! %s", all_item_list)
the_latest_one = all_item_list[-1]
if not item.get("cancel_in_db", None) or the_latest_one[-1] != item["cancel_in_db"][-1]:
# need to update the undone pointer in database
Expand Down Expand Up @@ -3491,6 +3499,7 @@ def on_cancel(self, messages):
meta.cancel_callback([(message.payload.member, message.payload.global_time, message.payload.packet)
for message in sub_messages])

# TODO(lfei): remove this after we have completely removed the undo message
def create_undo(self, message, sign_with_master=False, store=True, update=True, forward=True):
"""
Create a dispersy-undo-own or dispersy-undo-other message to undo MESSAGE.
Expand Down Expand Up @@ -3563,6 +3572,7 @@ def create_undo(self, message, sign_with_master=False, store=True, update=True,
self._dispersy.store_update_forward([msg], store, update, forward)
return msg

# TODO(lfei): remove this after we have completely removed the undo message
def check_undo(self, messages):
# Note: previously all MESSAGES have been checked to ensure that the sequence numbers are
# correct. this check takes into account the messages in the batch. hence, if one of these
Expand Down Expand Up @@ -3661,6 +3671,7 @@ def check_undo(self, messages):

yield message

# TODO(lfei): remove this after we have completely removed the undo message
def on_undo(self, messages):
"""
Undo a single message.
Expand Down

0 comments on commit 5b24637

Please sign in to comment.