from dataclasses import dataclass, InitVar
from enum import Enum, auto
from getpass import getuser
-from threading import Thread
from typing import (Any, Callable, Collection, Generic, Iterable, Iterator,
Optional, Self, Set, TypeVar)
from uuid import uuid4
# ourselves
-from ircplom.events import (
- AffectiveEvent, CrashingException, ExceptionEvent, QueueMixin)
+from ircplom.events import AffectiveEvent, QueueMixin
from ircplom.irc_conn import (
BaseIrcConnection, IrcConnAbortException, IrcMessage,
ILLEGAL_NICK_CHARS, ILLEGAL_NICK_FIRSTCHARS, ISUPPORT_DEFAULTS, PORT_SSL)
if self.db.port <= 0:
self.db.port = PORT_SSL
- def start_connecting(self) -> None:
- 'Start thread establishing connection, then triggering ._on_connect.'
-
- def connect(self) -> None:
- try:
- if self.conn:
- raise IrcConnAbortException('already connected')
- self.conn = self._cls_conn(
- hostname=self.db.hostname, port=self.db.port,
- _q_out=self._q_out, client_id=self.client_id)
- self._client_trigger('_on_connect')
- except IrcConnAbortException as e:
- self._log(f'failed to connect: {e}', alert=True)
- # catch _all_ just so they exit readably with the main loop
- except Exception as e: # pylint: disable=broad-exception-caught
- self._put(ExceptionEvent(CrashingException(e)))
-
+ def connect(self) -> None:
+ 'Attempt to open connection, on success perform session init steps.'
self.db.connection_state = 'connecting'
- Thread(target=connect, daemon=True, args=(self,)).start()
-
- def _on_connect(self) -> None:
- assert self.conn is not None
+ try:
+ self.conn = self._cls_conn(
+ hostname=self.db.hostname, port=self.db.port,
+ _q_out=self._q_out, client_id=self.client_id)
+ except IrcConnAbortException as e:
+ self.db.connection_state = f'failed to connect: {e}'
+ return
self.db.users['me'].nickuserhost = NickUserHost(user=getuser())
self.db.connection_state = 'connected'
self.caps.start_negotation()
def affect(self, target: ClientsDb) -> None:
target[self.payload.client_id] = self.payload
- self.payload.start_connecting()
+ # only run _after_ spot in ClientsDb secure, for ClientEvents to target
+ self.payload.connect()
@dataclass