diff options
author | joe <joe@jerkface.net> | 2017-07-10 20:30:10 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-07-10 20:30:10 -0400 |
commit | 2fdb0342f8cfcaf4924a0ce43e7fccb236eb0d5e (patch) | |
tree | fe013b9d665d6a6c03f6a35af017851f105115c0 /src/Network/KRPC/Method.hs | |
parent | c565ec07f37006a5abb7b3bc5a1b08013fbeb5d7 (diff) |
Fixed Tox decryption.
Diffstat (limited to 'src/Network/KRPC/Method.hs')
-rw-r--r-- | src/Network/KRPC/Method.hs | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/src/Network/KRPC/Method.hs b/src/Network/KRPC/Method.hs index 4d2be86d..da69d14b 100644 --- a/src/Network/KRPC/Method.hs +++ b/src/Network/KRPC/Method.hs | |||
@@ -38,76 +38,3 @@ import Network.DatagramServer.Types | |||
38 | import Network.DHT.Types | 38 | import Network.DHT.Types |
39 | 39 | ||
40 | 40 | ||
41 | -- | Method datatype used to describe method name, parameters and | ||
42 | -- return values of procedure. Client use a method to /invoke/, server | ||
43 | -- /implements/ the method to make the actual work. | ||
44 | -- | ||
45 | -- We use the following fantom types to ensure type-safiety: | ||
46 | -- | ||
47 | -- * param: Type of method parameters. | ||
48 | -- | ||
49 | -- * result: Type of return value of the method. | ||
50 | -- | ||
51 | newtype Method dht param result = Method { methodName :: QueryMethod dht } | ||
52 | |||
53 | deriving instance Eq (QueryMethod dht) => Eq (Method dht param result) | ||
54 | deriving instance Ord (QueryMethod dht) => Ord (Method dht param result) | ||
55 | deriving instance IsString (QueryMethod dht) => IsString (Method dht param result) | ||
56 | deriving instance BEncode (QueryMethod dht) => BEncode (Method dht param result) | ||
57 | |||
58 | -- | Example: | ||
59 | -- | ||
60 | -- @show (Method \"concat\" :: [Int] Int) == \"concat :: [Int] -> Int\"@ | ||
61 | -- | ||
62 | instance (Show (QueryMethod dht), Typeable a, Typeable b) => Show (Method dht a b) where | ||
63 | showsPrec _ = showsMethod | ||
64 | |||
65 | showsMethod :: forall dht a b. ( Show (QueryMethod dht), Typeable a , Typeable b ) => Method dht a b -> ShowS | ||
66 | showsMethod (Method name) = | ||
67 | -- showString (BC.unpack name) <> | ||
68 | shows (show name) <> | ||
69 | showString " :: " <> | ||
70 | shows paramsTy <> | ||
71 | showString " -> " <> | ||
72 | shows valuesTy | ||
73 | where | ||
74 | impossible = error "KRPC.showsMethod: impossible" | ||
75 | paramsTy = typeOf (impossible :: a) | ||
76 | valuesTy = typeOf (impossible :: b) | ||
77 | |||
78 | -- | In order to perform or handle KRPC query you need to provide | ||
79 | -- corresponding 'KRPC' class. | ||
80 | -- | ||
81 | -- Example: | ||
82 | -- | ||
83 | -- @ | ||
84 | -- data Ping = Ping Text deriving BEncode | ||
85 | -- data Pong = Pong Text deriving BEncode | ||
86 | -- | ||
87 | -- instance 'KRPC' Ping Pong where | ||
88 | -- method = \"ping\" | ||
89 | -- @ | ||
90 | -- | ||
91 | class ( Typeable req, Typeable resp, Envelope dht) | ||
92 | => KRPC dht req resp | req -> resp, resp -> req where | ||
93 | |||
94 | -- | Method name. Default implementation uses lowercased @req@ | ||
95 | -- datatype name. | ||
96 | -- | ||
97 | method :: Method dht req resp | ||
98 | |||
99 | -- TODO add underscores | ||
100 | default method :: (IsString (QueryMethod dht), Typeable req) => Method dht req resp | ||
101 | method = Method $ fromString $ L.map toLower $ show $ typeOf hole | ||
102 | where | ||
103 | hole = error "krpc.method: impossible" :: req | ||
104 | |||
105 | |||
106 | validateExchange :: dht req -> dht resp -> Bool | ||
107 | validateExchange _ _ = True | ||
108 | |||
109 | makeQueryExtra :: DHTData dht ip -> NodeId dht -> Proxy req -> Proxy resp -> IO (QueryExtra dht) | ||
110 | makeResponseExtra :: DHTData dht ip -> NodeId dht -> req -> Proxy resp -> IO (ResponseExtra dht) | ||
111 | |||
112 | messageSender :: dht req -> Proxy resp -> NodeId dht | ||
113 | messageResponder :: Proxy req -> dht resp -> NodeId dht | ||