Skip to content

Commit

Permalink
peer: Require connection attempt before XID
Browse files Browse the repository at this point in the history
The only time we do an XID is just prior to a connection attempt, we
should enforce this to simplify logic.
  • Loading branch information
sjlongland committed May 7, 2024
1 parent 236c9d0 commit 1dd227e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions aioax25/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def connect(self):
"""
if self._state is AX25PeerState.DISCONNECTED:
self._log.info("Initiating connection to remote peer")
self._set_conn_state(AX25PeerState.CONNECTING)
handler = AX25PeerConnectionHandler(self)
handler.done_sig.connect(self._on_connect_response)
handler._go()
Expand Down Expand Up @@ -887,6 +888,9 @@ def _negotiate(self, callback):
"""
Undertake negotiation with the peer station.
"""
# Sanity check, ensure we are in the CONNECTING state
assert self._state is AX25PeerState.CONNECTING

# Sanity check, don't call this if we know the station won't take it.
if self._protocol not in (AX25Version.UNKNOWN, AX25Version.AX25_22):
raise RuntimeError(
Expand Down Expand Up @@ -928,8 +932,8 @@ def _on_negotiate_result(self, response, **kwargs):
self._protocol = AX25Version.AX25_22

self._negotiated = True
self._log.debug("XID negotiation complete")
self._set_conn_state(AX25PeerState.DISCONNECTED)
self._log.debug("XID negotiation complete, resume connection")
self._set_conn_state(AX25PeerState.CONNECTING)

def _init_connection(self, extended):
"""
Expand Down

0 comments on commit 1dd227e

Please sign in to comment.