diff options
author | Joe Crayne <joe@jerkface.net> | 2020-01-25 03:32:00 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-25 19:18:12 -0500 |
commit | e3ec604c8b918eee0c88866679ed0444a36a2803 (patch) | |
tree | 936403466fc81d596e7c5b550cd7133d9c89638c | |
parent | 782aada5511ce8bdf8ae63fee189e6c0c9481e1d (diff) |
Show address utilities: showViaRelay and summarizeNodeInfo.
-rw-r--r-- | dht/src/Data/Tox/DHT/Multi.hs | 6 | ||||
-rw-r--r-- | dht/src/Network/Tox/TCP.hs | 5 |
2 files changed, 10 insertions, 1 deletions
diff --git a/dht/src/Data/Tox/DHT/Multi.hs b/dht/src/Data/Tox/DHT/Multi.hs index 4067ab46..378a46bc 100644 --- a/dht/src/Data/Tox/DHT/Multi.hs +++ b/dht/src/Data/Tox/DHT/Multi.hs | |||
@@ -14,7 +14,7 @@ import qualified Network.Tox.TCP.NodeId as TCP | |||
14 | import Data.Tox.Onion (OnionDestination,RouteId) | 14 | import Data.Tox.Onion (OnionDestination,RouteId) |
15 | import Data.Tox.Relay hiding (NodeInfo) | 15 | import Data.Tox.Relay hiding (NodeInfo) |
16 | import Network.Address as SockAddr (canonize) | 16 | import Network.Address as SockAddr (canonize) |
17 | import Network.Tox.TCP as TCP (ViaRelay(..), tcpConnectionRequest_) | 17 | import Network.Tox.TCP as TCP (ViaRelay(..), tcpConnectionRequest_, showViaRelay) |
18 | import Network.QueryResponse as QR (Tagged(..), Client) | 18 | import Network.QueryResponse as QR (Tagged(..), Client) |
19 | 19 | ||
20 | import Data.Dependent.Sum | 20 | import Data.Dependent.Sum |
@@ -128,6 +128,10 @@ nodeId :: DSum T Identity -> NodeId | |||
128 | nodeId (UDP :=> Identity ni ) = UDP.nodeId ni | 128 | nodeId (UDP :=> Identity ni ) = UDP.nodeId ni |
129 | nodeId (TCP :=> Identity (ViaRelay _ nid _)) = nid | 129 | nodeId (TCP :=> Identity (ViaRelay _ nid _)) = nid |
130 | 130 | ||
131 | summarizeNodeInfo :: NodeInfo -> String | ||
132 | summarizeNodeInfo (UDP :=> Identity ni ) = show ni | ||
133 | summarizeNodeInfo (TCP :=> Identity viarelay) = showViaRelay viarelay | ||
134 | |||
131 | relayNodeId :: TCP.ViaRelay -> UDP.NodeId | 135 | relayNodeId :: TCP.ViaRelay -> UDP.NodeId |
132 | relayNodeId (ViaRelay _ nid _) = nid | 136 | relayNodeId (ViaRelay _ nid _) = nid |
133 | 137 | ||
diff --git a/dht/src/Network/Tox/TCP.hs b/dht/src/Network/Tox/TCP.hs index a89dbced..1da302b6 100644 --- a/dht/src/Network/Tox/TCP.hs +++ b/dht/src/Network/Tox/TCP.hs | |||
@@ -423,6 +423,11 @@ newClient crypto store load lookupSender getRoute = do | |||
423 | data ViaRelay = ViaRelay (Maybe ConId) UDP.NodeId NodeInfo | 423 | data ViaRelay = ViaRelay (Maybe ConId) UDP.NodeId NodeInfo |
424 | deriving (Eq,Ord,Show) | 424 | deriving (Eq,Ord,Show) |
425 | 425 | ||
426 | showViaRelay :: ViaRelay -> String | ||
427 | showViaRelay (ViaRelay mcon nid tcp) = | ||
428 | "TCP:" ++ maybe "(oob)" (\(ConId con) -> "(" ++ show con ++ ")") mcon | ||
429 | ++ show nid ++ "@@" ++ show (nodeAddr tcp) | ||
430 | |||
426 | partitionRelay :: TransportA err NodeInfo (SessionData,RelayPacket) (Bool,RelayPacket) | 431 | partitionRelay :: TransportA err NodeInfo (SessionData,RelayPacket) (Bool,RelayPacket) |
427 | -> IO ( Transport err ViaRelay ByteString | 432 | -> IO ( Transport err ViaRelay ByteString |
428 | , TransportA err NodeInfo (SessionData,RelayPacket) (Bool,RelayPacket)) | 433 | , TransportA err NodeInfo (SessionData,RelayPacket) (Bool,RelayPacket)) |