Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 29 2018 14:22

    jaseemabid on watson

    (compare)

  • Nov 29 2018 14:22
    jaseemabid closed #43
  • Dec 11 2015 14:52

    jaseemabid on master

    gitignore .stack-work directory Remove lib dependencies tasty a… (compare)

  • Dec 05 2015 20:35

    jaseemabid on master

    README: add a link to the offic… new test data file: ubuntu 14.1… stack config file Delete cabal… and 2 more (compare)

  • Nov 30 2015 10:07

    jaseemabid on master

    Compartmentalize threads with b… Add writer module with seek sup… Cleanup tracker a bit, add docs… and 12 more (compare)

  • Nov 30 2015 10:07
    jaseemabid closed #44
  • Nov 16 2015 10:00
    dfordivam commented #44
  • Nov 16 2015 02:05
    jaseemabid synchronize #44
  • Nov 16 2015 02:05

    jaseemabid on concurrency

    Cleanup with explicit types, Co… Use library function to remove … Download blocks only once (compare)

  • Nov 14 2015 21:02
    jaseemabid synchronize #44
  • Nov 14 2015 21:02

    jaseemabid on concurrency

    Fix broken tests (compare)

  • Nov 14 2015 20:49
    jaseemabid closed #40
  • Nov 14 2015 20:49
    jaseemabid commented #40
  • Nov 14 2015 20:25
    jaseemabid synchronize #44
  • Nov 14 2015 20:25

    jaseemabid on concurrency

    Document concurrency model, v1 (compare)

  • Nov 14 2015 20:19
    jaseemabid opened #44
  • Nov 14 2015 20:16

    jaseemabid on concurrency

    Add writer module with seek sup… Cleanup tracker a bit, add docs… WIP, Implement concurrency spec… and 6 more (compare)

  • Nov 14 2015 19:44

    jaseemabid on concurrency

    Peer ID is pointless IP and po… (compare)

  • Nov 14 2015 19:43
    jaseemabid opened #43
  • Nov 14 2015 19:42

    jaseemabid on watson

    Use watson for micro issues `w… (compare)

Ramakrishnan Muthukrishnan
@vu3rdd
I am getting into meetings from 8. :(
Jaseem Abid
@jaseemabid
When will it be over?
Ramakrishnan Muthukrishnan
@vu3rdd
8-9, 9-10.
.. and I will be over by then. :(
Jaseem Abid
@jaseemabid
Alright!
Jaseem Abid
@jaseemabid
@vu3rdd Can we not apply d4d331f ?
We should use travis
Jaseem Abid
@jaseemabid
Tried to avoid double compilation but getting this wierd error
functorrent-0.1.0.0: unregistering (local file changes: functorrent.cabal)
functorrent-0.1.0.0: configure
Configuring functorrent-0.1.0.0...
functorrent-0.1.0.0: build
Preprocessing library functorrent-0.1.0.0...
In-place registering functorrent-0.1.0.0...
Preprocessing executable 'functorrent' for functorrent-0.1.0.0...
Warning: modules not listed in functorrent.cabal for 'functorrent' component (add to other-modules):
    FuncTorrent.Bencode
    FuncTorrent.ControlThread
    FuncTorrent.Core
    FuncTorrent.Logger
    FuncTorrent.Metainfo
    FuncTorrent.Peer
    FuncTorrent.Tracker
    FuncTorrent.Utils
    FuncTorrent.Writer
functorrent-0.1.0.0: copy/register
Installing library in
/Users/j/Projects/ft/.stack-work/install/x86_64-osx/lts-3.11/7.10.2/lib/x86_64-osx-ghc-7.10.2/functorrent-0.1.0.0-1RrYqrOfxbfJ3MYuggDuOs
Installing executable(s) in
/Users/j/Projects/ft/.stack-work/ins
Jaseem Abid
@jaseemabid
Also f46f015. Remove nix, but why gitter?
Picked these 2 commits
c92357b Remove lib dependencies tasty and hunit
426b94d gitignore .stack-work directory
Jaseem Abid
@jaseemabid
@vu3rdd Busy today?
Ramakrishnan Muthukrishnan
@vu3rdd
I am totally stumped on a very simple thing. How do we maintain statistics of uploaded/downloaded bytes. Sounds simple. I thought of using a State Monad in the FileSystem Module..
but I just can't fit it in an elegant way. :(
@jaseemabid ^^
Jaseem Abid
@jaseemabid
Cant we keep track of uploaded peices and multiply by piece size?
Ah, when I think about it, you need to remember the number of times the piece was transferred
Ramakrishnan Muthukrishnan
@vu3rdd
yes, the best place to do that is at the filesystem module when you get readPiece/writePiece message.
it would have been nice to use a StateT Stats IO () type.
where Stats is "data Stats = Stats {bytesUploaded :: Integer, bytesDownloaded :: Integer }
Ramakrishnan Muthukrishnan
@vu3rdd
This message was deleted
run :: PieceMap -> MsgChannel -> Handle -> IO ()
run pieceMap c handle =
  recvMsg >>= sendResponse
  where
    recvMsg = readChan c
    sendResponse msg =
      case msg of
      ReadPiece n len' var -> do
        bs <- readPiece n len'
        putMVar var (Piece n bs)
      WritePiece (Piece n bs) -> do
        writePiece n bs
      VerifyPiece n var -> do
        isHashValid <- verifyPiece n
        putMVar var isHashValid
    readPiece n len' = do
      let offset = pieceNumToOffset pieceMap n
      readFileAtOffset handle offset len'
    writePiece n piece = do
      let offset = pieceNumToOffset pieceMap n
      writeFileAtOffset handle offset piece
    verifyPiece n = do
      let offset = pieceNumToOffset pieceMap n
          hash'  = hash (pieceMap ! n)
          len'   = len (pieceMap ! n)
      bs' <- readFileAtOffset handle offset len'
      return $ verifyHash bs' hash'
this is what I currently have.
but having Stat will totally break it. :(
Ramakrishnan Muthukrishnan
@vu3rdd
OK, I solved it this way:
run :: PieceMap -> MsgChannel -> Handle -> IO ()
run pieceMap c handle = do
  _ <- runStateT (run' pieceMap c handle) initialStats
  return ()
    where initialStats = Stats { bytesRead = 0
                               , bytesWritten = 0 }

run' :: PieceMap -> MsgChannel -> Handle -> StateT Stats IO ()
run' pieceMap c handle = do
  msg <- liftIO recvMsg
  liftIO $ sendResponse msg
  updateState msg 
  where
    recvMsg = readChan c
    sendResponse msg =
      case msg of
      ReadPiece n len' var -> do
        bs <- readPiece n len'
        putMVar var (Piece n bs)
      WritePiece (Piece n bs) -> do
        writePiece n bs
      VerifyPiece n var -> do
        isHashValid <- verifyPiece n
        putMVar var isHashValid
    readPiece n len' = do
      let offset = pieceNumToOffset pieceMap n
      readFileAtOffset handle offset len'
    writePiece n piece = do
      let offset = pieceNumToOffset pieceMap n
      writeFileAtOffset handle offset piece
    verifyPiece n = do
      let offset = pieceNumToOffset pieceMap n
          hash'  = hash (pieceMap ! n)
          len'   = len (pieceMap ! n)
      bs' <- readFileAtOffset handle offset len'
      return $ verifyHash bs' hash'
    updateState (ReadPiece _ l _) = do
      st <- get
      modify (\st -> st {bytesRead = (bytesRead st) + l})
    updateState (WritePiece (Piece _ bs)) = do
      st <- get
      modify (\st -> st {bytesWritten = (bytesWritten st) + (fromIntegral (BS.length bs))})
    updateState _ = modify id
there must be better ways to do this.
Ramakrishnan Muthukrishnan
@vu3rdd
hmm.. lots of stupidity there. no need for those get calls.
run' :: PieceMap -> MsgChannel -> Handle -> StateT Stats IO ()
run' pieceMap c handle = do
  msg <- liftIO recvMsg
  liftIO $ sendResponse msg
  updateState msg 
  where
    recvMsg = readChan c
    sendResponse msg =
      case msg of
      ReadPiece n len' var -> do
        bs <- readPiece n len'
        putMVar var (Piece n bs)
      WritePiece (Piece n bs) ->
        writePiece n bs
      VerifyPiece n var -> do
        isHashValid <- verifyPiece n
        putMVar var isHashValid
    readPiece n len' = do
      let offset = pieceNumToOffset pieceMap n
      readFileAtOffset handle offset len'
    writePiece n piece = do
      let offset = pieceNumToOffset pieceMap n
      writeFileAtOffset handle offset piece
    verifyPiece n = do
      let offset = pieceNumToOffset pieceMap n
          hash'  = hash (pieceMap ! n)
          len'   = len (pieceMap ! n)
      bs' <- readFileAtOffset handle offset len'
      return $ verifyHash bs' hash'
    updateState (ReadPiece _ l _) =
      modify (\st -> st {bytesRead = bytesRead st + l})
    updateState (WritePiece (Piece _ bs)) =
      modify (\st -> st {bytesWritten = bytesWritten st + fromIntegral (BS.length bs)})
    updateState _ = modify id
@jaseemabid
Ramakrishnan Muthukrishnan
@vu3rdd
One problem with the independent threads with an associated msg channel is that even if the thread is dead, the channel could be active and misleading. It is just buffering messages but no one is acting on it.
Jaseem Abid
@jaseemabid
Yes, there is no way to close a channel. I noticed that.
Know any workaround ?
Ramakrishnan Muthukrishnan
@vu3rdd
no. I guess we should just make sure that the thread is alive. Most of our workers are supposed to run till completion.
Jaseem Abid
@jaseemabid
@vu3rdd When are you free to sit again?
Ramakrishnan Muthukrishnan
@vu3rdd
@jaseemabid I am in Kerala till 2nd evening. Can we do via gitter? I am totally free today, tomorrow and day after.
Implemented the rsync algorithm in Haskell. Not a great implementation, but it was surprisingly clear and simple in Haskell. https://github.com/vu3rdd/hs-rsync
Ramakrishnan Muthukrishnan
@vu3rdd
Nice article on Free Monads.
Ramakrishnan Muthukrishnan
@vu3rdd
I just wrote up a blog post on the rsync algorithm: https://rkrishnan.org/posts/2015-12-30-rsync-algorithm.md.html
Jaseem Abid
@jaseemabid
Nice.
I missed these messages. Just saw them
@vu3rdd There?
Jaseem Abid
@jaseemabid
Super sweet idea.
Antonio Pires
@anastiel
project is really?
Jaseem Abid
@jaseemabid
@anastiel Eh?