remove overly verbose comments

This commit is contained in:
Alex Stokes 2019-09-24 15:35:48 -07:00
parent e6a0361e09
commit ada4d48b6e
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086
2 changed files with 0 additions and 38 deletions

View File

@ -39,34 +39,26 @@ class Multiselect(IMultiselectMuxer):
:return: selected protocol name, handler function :return: selected protocol name, handler function
:raise MultiselectError: raised when negotiation failed :raise MultiselectError: raised when negotiation failed
""" """
# Perform handshake to ensure multiselect protocol IDs match
await self.handshake(communicator) await self.handshake(communicator)
# Read and respond to commands until a valid protocol ID is sent
while True: while True:
# Read message
try: try:
command = await communicator.read() command = await communicator.read()
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
raise MultiselectError(error) raise MultiselectError(error)
# Command is ls or a protocol
if command == "ls": if command == "ls":
# TODO: handle ls command # TODO: handle ls command
pass pass
else: else:
protocol = TProtocol(command) protocol = TProtocol(command)
if protocol in self.handlers: if protocol in self.handlers:
# Tell counterparty we have decided on a protocol
try: try:
await communicator.write(protocol) await communicator.write(protocol)
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
raise MultiselectError(error) raise MultiselectError(error)
# Return the decided on protocol
return protocol, self.handlers[protocol] return protocol, self.handlers[protocol]
# Tell counterparty this protocol was not found
try: try:
await communicator.write(PROTOCOL_NOT_FOUND_MSG) await communicator.write(PROTOCOL_NOT_FOUND_MSG)
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
@ -78,30 +70,22 @@ class Multiselect(IMultiselectMuxer):
:param communicator: communicator to use :param communicator: communicator to use
:raise MultiselectError: raised when handshake failed :raise MultiselectError: raised when handshake failed
""" """
# TODO: Use format used by go repo for messages
# Send our MULTISELECT_PROTOCOL_ID to other party
try: try:
await communicator.write(MULTISELECT_PROTOCOL_ID) await communicator.write(MULTISELECT_PROTOCOL_ID)
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
raise MultiselectError(error) raise MultiselectError(error)
# Read in the protocol ID from other party
try: try:
handshake_contents = await communicator.read() handshake_contents = await communicator.read()
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
raise MultiselectError(error) raise MultiselectError(error)
# Confirm that the protocols are the same
if not validate_handshake(handshake_contents): if not validate_handshake(handshake_contents):
raise MultiselectError( raise MultiselectError(
"multiselect protocol ID mismatch: " "multiselect protocol ID mismatch: "
f"received handshake_contents={handshake_contents}" f"received handshake_contents={handshake_contents}"
) )
# Handshake succeeded if this point is reached
def validate_handshake(handshake_contents: str) -> bool: def validate_handshake(handshake_contents: str) -> bool:
""" """
@ -109,7 +93,4 @@ def validate_handshake(handshake_contents: str) -> bool:
:param handshake_contents: contents of handshake message :param handshake_contents: contents of handshake message
:return: true if handshake is complete, false otherwise :return: true if handshake is complete, false otherwise
""" """
# TODO: Modify this when format used by go repo for messages
# is added
return handshake_contents == MULTISELECT_PROTOCOL_ID return handshake_contents == MULTISELECT_PROTOCOL_ID

View File

@ -23,27 +23,19 @@ class MultiselectClient(IMultiselectClient):
:param stream: stream to communicate with multiselect over :param stream: stream to communicate with multiselect over
:raise MultiselectClientError: raised when handshake failed :raise MultiselectClientError: raised when handshake failed
""" """
# TODO: Use format used by go repo for messages
# Send our MULTISELECT_PROTOCOL_ID to counterparty
try: try:
await communicator.write(MULTISELECT_PROTOCOL_ID) await communicator.write(MULTISELECT_PROTOCOL_ID)
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
raise MultiselectClientError(error) raise MultiselectClientError(error)
# Read in the protocol ID from other party
try: try:
handshake_contents = await communicator.read() handshake_contents = await communicator.read()
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
raise MultiselectClientError(str(error)) raise MultiselectClientError(str(error))
# Confirm that the protocols are the same
if not validate_handshake(handshake_contents): if not validate_handshake(handshake_contents):
raise MultiselectClientError("multiselect protocol ID mismatch") raise MultiselectClientError("multiselect protocol ID mismatch")
# Handshake succeeded if this point is reached
async def select_one_of( async def select_one_of(
self, protocols: Sequence[TProtocol], communicator: IMultiselectCommunicator self, protocols: Sequence[TProtocol], communicator: IMultiselectCommunicator
) -> TProtocol: ) -> TProtocol:
@ -56,11 +48,8 @@ class MultiselectClient(IMultiselectClient):
:return: selected protocol :return: selected protocol
:raise MultiselectClientError: raised when protocol negotiation failed :raise MultiselectClientError: raised when protocol negotiation failed
""" """
# Perform handshake to ensure multiselect protocol IDs match
await self.handshake(communicator) await self.handshake(communicator)
# For each protocol, attempt to select that protocol
# and return the first protocol selected
for protocol in protocols: for protocol in protocols:
try: try:
selected_protocol = await self.try_select(communicator, protocol) selected_protocol = await self.try_select(communicator, protocol)
@ -68,7 +57,6 @@ class MultiselectClient(IMultiselectClient):
except MultiselectClientError: except MultiselectClientError:
pass pass
# No protocols were found, so return no protocols supported error
raise MultiselectClientError("protocols not supported") raise MultiselectClientError("protocols not supported")
async def try_select( async def try_select(
@ -81,20 +69,16 @@ class MultiselectClient(IMultiselectClient):
:raise MultiselectClientError: raised when protocol negotiation failed :raise MultiselectClientError: raised when protocol negotiation failed
:return: selected protocol :return: selected protocol
""" """
# Tell counterparty we want to use protocol
try: try:
await communicator.write(protocol) await communicator.write(protocol)
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
raise MultiselectClientError(error) raise MultiselectClientError(error)
# Get what counterparty says in response
try: try:
response = await communicator.read() response = await communicator.read()
except MultiselectCommunicatorError as error: except MultiselectCommunicatorError as error:
raise MultiselectClientError(str(error)) raise MultiselectClientError(str(error))
# Return protocol if response is equal to protocol or raise error
if response == protocol: if response == protocol:
return protocol return protocol
if response == PROTOCOL_NOT_FOUND_MSG: if response == PROTOCOL_NOT_FOUND_MSG:
@ -108,7 +92,4 @@ def validate_handshake(handshake_contents: str) -> bool:
:param handshake_contents: contents of handshake message :param handshake_contents: contents of handshake message
:return: true if handshake is complete, false otherwise :return: true if handshake is complete, false otherwise
""" """
# TODO: Modify this when format used by go repo for messages
# is added
return handshake_contents == MULTISELECT_PROTOCOL_ID return handshake_contents == MULTISELECT_PROTOCOL_ID