Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
alanz committed Jun 3, 2014
1 parent b5906d5 commit c431584
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
21 changes: 21 additions & 0 deletions src/Network/TeleHash/Ext/Seek.hs
Expand Up @@ -4,6 +4,8 @@ module Network.TeleHash.Ext.Seek
ext_seek
, seek_auto
, peer_send

, manual_seek
) where

import Control.Exception
Expand All @@ -17,6 +19,7 @@ import System.Time

import Network.TeleHash.Dht
import Network.TeleHash.Ext.Path
import Network.TeleHash.Hn
import Network.TeleHash.Packet
import Network.TeleHash.Paths
import Network.TeleHash.SwitchApi
Expand Down Expand Up @@ -301,6 +304,24 @@ void seek_send(switch_t s, seek_t sk, hn_t to)
}
-}

-- ---------------------------------------------------------------------

arbitrary_hashname :: TeleHash HashName
arbitrary_hashname = do
hn <- randomHEX 32
return (HN hn)

-- |Manually initiate a seek to each seed for itself, purely for experimentation from the UI
manual_seek :: TeleHash ()
manual_seek = do
sw <- get
forM_ (Set.toList $ swSeeds sw) $ \seed -> do
rhn <- arbitrary_hashname
void $ hn_get rhn -- Make sure we have a record for it
sk <- seek_get rhn
seek_send sk seed


-- ---------------------------------------------------------------------

-- |Create a seek to this hn and initiate connect This is called as
Expand Down
23 changes: 0 additions & 23 deletions src/Network/TeleHash/Hn.hs
Expand Up @@ -19,7 +19,6 @@ import Network.TeleHash.Crypt
import Network.TeleHash.Packet
import Network.TeleHash.Path
import Network.TeleHash.Paths
-- import Network.TeleHash.SwitchApi
import Network.TeleHash.Types
import Network.TeleHash.Utils

Expand Down Expand Up @@ -405,27 +404,5 @@ hn_get hn = do
hc <- newHN hn
return hc

{-
hn_t hn_get(xht_t index, unsigned char *bin)
{
hn_t hn;
unsigned char hex[65];
if(!bin) return NULL;
util_hex(bin,32,hex);
hn = xht_get(index, (const char*)hex);
if(hn) return hn;
// init new hashname container
if(!(hn = malloc(sizeof (struct hn_struct)))) return NULL;
memset(hn,0,sizeof (struct hn_struct));
memcpy(hn->hashname, bin, 32);
memcpy(hn->hexname, hex, 65);
xht_set(index, (const char*)hn->hexname, (void*)hn);
if(!(hn->paths = malloc(sizeof (path_t)))) return hn_free(hn);
hn->paths[0] = NULL;
return hn;
}
-}

-- ---------------------------------------------------------------------
2 changes: 1 addition & 1 deletion src/Network/TeleHash/SwitchApi.hs
Expand Up @@ -115,12 +115,12 @@ switch_receive rxPacket path timeNow = do
OpenPacket _b _bs -> do
-- process open packet
open <- crypt_deopenize rxPacket
logP $ "DEOPEN " ++ showJson (doJs open)
case open of
DeOpenizeVerifyFail -> do
logT $ "DEOPEN fail for " ++ show rxPacket
return ()
deOpenizeResult -> do
logP $ "DEOPEN " ++ showJson (doJs open)
logT $ "receive.deopenize verified ok " -- ++ show open
let minner = parseJsVal (doJs open) :: Maybe OpenizeInner
case minner of
Expand Down
4 changes: 4 additions & 0 deletions tft.hs
Expand Up @@ -340,6 +340,10 @@ app = do
chStr <- showAllDht
logR chStr

| isPrefixOf "/seek" l -> do
logR $ "Seeking all seeds"
manual_seek

| otherwise -> do
-- default send as message
cid <- getChatCurrent
Expand Down

0 comments on commit c431584

Please sign in to comment.