diff --git a/libp2p/chronosstream.nim b/libp2p/chronosstream.nim index 736d74f..98b1612 100644 --- a/libp2p/chronosstream.nim +++ b/libp2p/chronosstream.nim @@ -8,9 +8,9 @@ ## those terms. import chronos -import readerwriter +import stream -type ChronosStream* = ref object of ReadWrite +type ChronosStream* = ref object of LPStream reader: AsyncStreamReader writer: AsyncStreamWriter server: StreamServer diff --git a/libp2p/connection.nim b/libp2p/connection.nim index 2cf9527..c0c29f6 100644 --- a/libp2p/connection.nim +++ b/libp2p/connection.nim @@ -8,16 +8,16 @@ ## those terms. import chronos -import peerinfo, multiaddress, readerwriter, peerinfo, varint, vbuffer +import peerinfo, multiaddress, stream, peerinfo, varint, vbuffer const DefaultReadSize: uint = 64*1024 type - Connection* = ref object of ReadWrite + Connection* = ref object of LPStream peerInfo*: PeerInfo - stream: ReadWrite + stream: LPStream -proc newConnection*(stream: ReadWrite): Connection = +proc newConnection*(stream: LPStream): Connection = ## create a new Connection for the specified async reader/writer new result result.stream = stream diff --git a/libp2p/stream.nim b/libp2p/stream.nim new file mode 100644 index 0000000..e5f6544 --- /dev/null +++ b/libp2p/stream.nim @@ -0,0 +1,51 @@ +## Nim-LibP2P +## Copyright (c) 2018 Status Research & Development GmbH +## Licensed under either of +## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +## * MIT license ([LICENSE-MIT](LICENSE-MIT)) +## at your option. +## This file may not be copied, modified, or distributed except according to +## those terms. + +import chronos + +type LPStream* = ref object of RootObj + closed*: bool + +method read*(s: LPStream, n = -1): Future[seq[byte]] + {.base, async.} = + discard + +method readExactly*(s: LPStream, pbytes: pointer, nbytes: int): Future[void] + {.base, async.} = + discard + +method readLine*(s: LPStream, limit = 0, sep = "\r\n"): Future[string] + {.base, async.} = + discard + +method readOnce*(s: LPStream, pbytes: pointer, nbytes: int): Future[int] + {.base, async.} = + discard + +method readUntil*(s: LPStream, + pbytes: pointer, nbytes: int, + sep: seq[byte]): Future[int] + {.base, async.} = + discard + +method write*(s: LPStream, pbytes: pointer, nbytes: int) + {.base, async.} = + discard + +method write*(s: LPStream, msg: string, msglen = -1) + {.base, async.} = + discard + +method write*(s: LPStream, msg: seq[byte], msglen = -1) + {.base, async.} = + discard + +method close*(s: LPStream) + {.base, async.} = + discard diff --git a/libp2p/transport.nim b/libp2p/transport.nim index f1c5a36..3fc580c 100644 --- a/libp2p/transport.nim +++ b/libp2p/transport.nim @@ -8,7 +8,7 @@ ## those terms. import chronos -import peerinfo, connection, multiaddress, multicodec, readerwriter +import peerinfo, connection, multiaddress, multicodec type ConnHandler* = proc (conn: Connection): Future[void] {.gcsafe.} diff --git a/tests/testmultistreamselect.nim b/tests/testmultistreamselect.nim index 383a5ba..d189344 100644 --- a/tests/testmultistreamselect.nim +++ b/tests/testmultistreamselect.nim @@ -1,12 +1,12 @@ import unittest, strutils, sequtils, sugar import chronos import ../libp2p/connection, ../libp2p/multistreamselect, - ../libp2p/readerwriter, ../libp2p/connection, ../libp2p/multiaddress, + ../libp2p/stream, ../libp2p/connection, ../libp2p/multiaddress, ../libp2p/transport, ../libp2p/tcptransport ## Mock stream for select test type - TestSelectStream = ref object of ReadWrite + TestSelectStream = ref object of LPStream step*: int method readExactly*(s: TestSelectStream, @@ -41,7 +41,7 @@ proc newTestSelectStream(): TestSelectStream = ## Mock stream for handles test type - TestHandlesStream = ref object of ReadWrite + TestHandlesStream = ref object of LPStream step*: int method readExactly*(s: TestHandlesStream, @@ -78,7 +78,7 @@ proc newTestHandlesStream(): TestHandlesStream = type LsHandler = proc(procs: seq[byte]): Future[void] - TestLsStream = ref object of ReadWrite + TestLsStream = ref object of LPStream step*: int ls*: LsHandler @@ -121,7 +121,7 @@ proc newTestLsStream(ls: LsHandler): TestLsStream = type NaHandler = proc(procs: string): Future[void] - TestNaStream = ref object of ReadWrite + TestNaStream = ref object of LPStream step*: int na*: NaHandler