diff options
Diffstat (limited to 'src/Network/Tox/NodeId.hs')
-rw-r--r-- | src/Network/Tox/NodeId.hs | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs index 3a732b43..d5da692a 100644 --- a/src/Network/Tox/NodeId.hs +++ b/src/Network/Tox/NodeId.hs | |||
@@ -33,7 +33,10 @@ module Network.Tox.NodeId | |||
33 | , parseNoSpamId | 33 | , parseNoSpamId |
34 | , nospam64 | 34 | , nospam64 |
35 | , nospam16 | 35 | , nospam16 |
36 | , verifyChecksum) where | 36 | , verifyChecksum |
37 | , ToxContact(..) | ||
38 | , ToxProgress(..) | ||
39 | ) where | ||
37 | 40 | ||
38 | import Control.Applicative | 41 | import Control.Applicative |
39 | import Control.Arrow | 42 | import Control.Arrow |
@@ -617,3 +620,78 @@ solveBase64NoSpamID b64digits pub = do | |||
617 | let nospam' = fromIntegral (n64' `shiftR` 32) | 620 | let nospam' = fromIntegral (n64' `shiftR` 32) |
618 | cksum' = fromIntegral (n64' `shiftR` 16) | 621 | cksum' = fromIntegral (n64' `shiftR` 16) |
619 | return $ NoSpamId (NoSpam nospam' (Just cksum')) pub | 622 | return $ NoSpamId (NoSpam nospam' (Just cksum')) pub |
623 | |||
624 | -- | This type indicates a roster-link relationship between a local toxid and a | ||
625 | -- remote toxid. Note that these toxids are represented as the type 'NodeId' | ||
626 | -- even though they are long-term keys rather than the public keys of Tox DHT | ||
627 | -- nodes. | ||
628 | data ToxContact = ToxContact NodeId{-me-} NodeId{-them-} | ||
629 | deriving (Eq,Ord) | ||
630 | |||
631 | instance Show ToxContact where show = show . showToxContact_ | ||
632 | |||
633 | showToxContact_ :: ToxContact -> String | ||
634 | showToxContact_ (ToxContact me them) = show me ++ ":" ++ show them | ||
635 | |||
636 | -- | This type indicates the progress of a tox encrypted friend link | ||
637 | -- connection. Two scenarios are illustrated below. The parenthesis show the | ||
638 | -- current 'G.Status' 'ToxProgress' of the session. | ||
639 | -- | ||
640 | -- | ||
641 | -- Perfect handshake scenario: | ||
642 | -- | ||
643 | -- Peer 1 Peer 2 | ||
644 | -- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) | ||
645 | -- Cookie request -> | ||
646 | -- <- Cookie response | ||
647 | -- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) | ||
648 | -- Handshake packet -> | ||
649 | -- * accepts connection | ||
650 | -- (InProgress AwaitingSessionPacket) | ||
651 | -- <- Handshake packet | ||
652 | -- *accepts connection | ||
653 | -- (InProgress AwaitingSessionPacket) | ||
654 | -- Encrypted packet -> <- Encrypted packet | ||
655 | -- *confirms connection *confirms connection | ||
656 | -- (Established) (Established) | ||
657 | -- | ||
658 | -- Connection successful. | ||
659 | -- | ||
660 | -- Encrypted packets -> <- Encrypted packets | ||
661 | -- | ||
662 | -- | ||
663 | -- | ||
664 | -- | ||
665 | -- More realistic handshake scenario: | ||
666 | -- Peer 1 Peer 2 | ||
667 | -- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) | ||
668 | -- Cookie request -> *packet lost* | ||
669 | -- Cookie request -> | ||
670 | -- <- Cookie response | ||
671 | -- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) | ||
672 | -- | ||
673 | -- *Peer 2 randomly starts new connection to peer 1 | ||
674 | -- (InProgress AcquiringCookie) | ||
675 | -- <- Cookie request | ||
676 | -- Cookie response -> | ||
677 | -- (InProgress AwaitingHandshake) | ||
678 | -- | ||
679 | -- Handshake packet -> <- Handshake packet | ||
680 | -- *accepts connection * accepts connection | ||
681 | -- (InProgress AwaitingSessionPacket) (InProgress AwaitingSessionPacket) | ||
682 | -- | ||
683 | -- Encrypted packet -> <- Encrypted packet | ||
684 | -- *confirms connection *confirms connection | ||
685 | -- (Established) (Established) | ||
686 | -- | ||
687 | -- Connection successful. | ||
688 | -- | ||
689 | -- Encrypted packets -> <- Encrypted packets | ||
690 | data ToxProgress | ||
691 | = AwaitingDHTKey -- ^ Waiting to receive their DHT key. | ||
692 | | AcquiringIPAddress -- ^ Searching DHT to obtain their node's IP & port. | ||
693 | | AcquiringCookie -- ^ Attempting to obtain a cookie. | ||
694 | | AwaitingHandshake -- ^ Waiting to receive a handshake. | ||
695 | | AwaitingSessionPacket -- ^ Connection is "accepted" but not yet "confirmed". | ||
696 | deriving (Eq,Ord,Enum,Show) | ||
697 | |||