Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: adding binary transfer with 3 MB/s performance #89

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4403d3b
Implement fresh UTP endpoint into IPv8
Eragoneq Mar 18, 2024
22c2199
Peer selection update
Eragoneq Mar 20, 2024
44906bc
First version transfer request
Eragoneq Mar 22, 2024
1c780c5
Add puncturing into the connection
Eragoneq Mar 24, 2024
b225e79
add possibility to listen for individual utp messages in UtpEndpoint.…
PieterCarton Apr 1, 2024
0fb5aab
fix missing method reference
PieterCarton Apr 4, 2024
fc5ba49
actually add missing reference
PieterCarton Apr 4, 2024
626ab8c
final fix
PieterCarton Apr 4, 2024
1197174
final fix for getServerSocket method
PieterCarton Apr 4, 2024
c6b64cb
First version of IPv8 integration
Eragoneq Apr 6, 2024
6141b53
Add channel for messages
Eragoneq Apr 6, 2024
19efe95
correctly set source ip and port of copied datagram packet in UtpIPv8…
PieterCarton Apr 6, 2024
7b7d7dd
Allow for IPv8 file transfer
Eragoneq Apr 7, 2024
f7e1867
Don't allow client to crash the app when not connected
Eragoneq Apr 7, 2024
0b2e2ee
Remove references to old endpoint
Eragoneq Apr 8, 2024
a6adba0
Add custom UTP community
Eragoneq Apr 8, 2024
854892c
Merge pull request #1 from Eragoneq/ipv8_integration
Eragoneq Apr 8, 2024
1843cec
Add comments to communication code
Eragoneq Apr 8, 2024
2832be0
Merge branch 'ipv8_integration'
Eragoneq Apr 8, 2024
3e4a42d
Update Serialization.kt with auto functionality
Eragoneq Apr 9, 2024
9b900b2
Add custom payloads and basic handlers
Eragoneq Apr 9, 2024
baaa761
Implement TransferRequest
Eragoneq Apr 9, 2024
dd3e50b
Move connection code to ipv8 library
Eragoneq Apr 11, 2024
0c1b03f
Fix missing closing of client connection
Eragoneq Apr 12, 2024
50f5fca
Allow internal transfer without request
Eragoneq Apr 12, 2024
8f766de
Fix infinite loop cancellation issue
Eragoneq Apr 12, 2024
20400fe
Add heartbeat loop
Eragoneq Apr 12, 2024
916b85e
Fix random data functionality
Eragoneq Apr 12, 2024
ab4db56
Fix Heartbeat code
Eragoneq Apr 14, 2024
f3fb94e
Modify random data sending
Eragoneq Apr 14, 2024
d5aa2f9
Merge pull request #2 from Eragoneq/community-extensions
Eragoneq Apr 14, 2024
452e6a1
Fix buffer overflow issue
Eragoneq Apr 14, 2024
02787d9
allow for listening to outgoing packets in UtpIPv8 endpoint
PieterCarton Apr 16, 2024
fea0456
test utp datagram prefix
PieterCarton Apr 16, 2024
1733f4e
add test for utp endpoint behaviour when sending file
PieterCarton Apr 16, 2024
c8a8060
Comment out unused print logs
Eragoneq Apr 16, 2024
9f9b119
Make heartbeat job explicit
Eragoneq Apr 16, 2024
9a577ae
Fix incoming data check
Eragoneq Apr 16, 2024
33f52a7
Fully test UtpCommunity class
Eragoneq Apr 16, 2024
fcffb52
Refactor data sending code
Eragoneq Apr 16, 2024
7094023
Test UtpHelper class
Eragoneq Apr 16, 2024
6a8e1c1
add receiver test for UtpIPv8Endpoint
PieterCarton Apr 17, 2024
9ca91d9
Merge branch 'utp-endpoint-unit-tests'
PieterCarton Apr 17, 2024
ff5053a
merge IPv8UtpEndpoint integration tests from branch utp-endpoint-unit…
PieterCarton Apr 17, 2024
4ec94f1
Merge pull request #3 from Eragoneq/misc-fix-test
Eragoneq Apr 17, 2024
c0b2424
Allow for buffer size mocking
Eragoneq Apr 17, 2024
af6ffa9
Add explicit heap size to stop test from throwing OOM error
Eragoneq Apr 17, 2024
2ddc25e
merge with master
PieterCarton Apr 18, 2024
765bb62
Add updates based on heartbeats
Eragoneq Apr 18, 2024
2ad644d
Use master branch of the library code
Eragoneq Apr 18, 2024
c0590f8
Merge branch 'master' of https://github.com/Eragoneq/kotlin-ipv8
PieterCarton Apr 18, 2024
d02720b
Add documentation
Eragoneq Apr 19, 2024
aba5aeb
Add a few more comments
Eragoneq Apr 19, 2024
3b0953d
Update docs
Eragoneq Apr 19, 2024
6454fa3
Merge pull request #4 from Eragoneq/documentation
Eragoneq Apr 19, 2024
4bef0c3
Use release version of library
Eragoneq Apr 19, 2024
49025f0
modify CWND_INCREASE_PER_RTT of UTP to 30000
PieterCarton Apr 19, 2024
15a134d
Merge branch 'master' of https://github.com/Eragoneq/kotlin-ipv8
PieterCarton Apr 19, 2024
a0f0da6
Update UtpBinaryTransfer.md
Eragoneq Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add puncturing into the connection
  • Loading branch information
Eragoneq committed Mar 24, 2024
commit 1c780c5ccddb85379c953fb9bc5f0136dddf0015
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ object IPv8Android {
connectivityManager,
)

val utpEndpoint = UtpEndpoint(
13377,
InetAddress.getByName("0.0.0.0")
)
val utpEndpoint =
UtpEndpoint(
13377,
InetAddress.getByName("0.0.0.0")
)

val bluetoothManager =
application.getSystemService<BluetoothManager>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import nl.tudelft.ipv8.messaging.serializeLong
import nl.tudelft.ipv8.messaging.serializeUChar
import nl.tudelft.ipv8.messaging.serializeUInt

class TransferRequestPayload(
data class TransferRequestPayload(
val port: Int,
val status: TransferStatus,
var dataSize: Int = 0
val dataSize: Int = 0
): Serializable {
override fun serialize(): ByteArray {
return serializeLong(port.toLong()) + serializeUInt(status.ordinal.toUInt()) + serializeLong(dataSize.toLong())
Expand Down Expand Up @@ -44,4 +44,8 @@ class TransferRequestPayload(
DECLINE
}

enum class TransferType {
FILE,
RANDOM_DATA
}
}
81 changes: 60 additions & 21 deletions ipv8/src/main/java/nl/tudelft/ipv8/messaging/utp/UtpEndpoint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import mu.KotlinLogging
import net.utp4j.channels.UtpServerSocketChannel
import net.utp4j.channels.UtpSocketChannel
import net.utp4j.channels.futures.UtpReadListener
import net.utp4j.channels.UtpSocketState
import net.utp4j.channels.impl.UtpServerSocketChannelImpl
import net.utp4j.channels.impl.UtpSocketChannelImpl
import net.utp4j.channels.impl.alg.UtpAlgConfiguration
import nl.tudelft.ipv8.IPv4Address
import nl.tudelft.ipv8.Peer
import nl.tudelft.ipv8.messaging.Endpoint
import nl.tudelft.ipv8.messaging.utp.listener.RawResourceListener
import java.io.IOException
import java.net.DatagramPacket
import java.net.DatagramSocket
import java.net.InetAddress
import java.net.InetSocketAddress
import java.nio.ByteBuffer

private val logger = KotlinLogging.logger {}

class UtpEndpoint(
private val port: Int,
val port: Int,
private val ip: InetAddress,
) : Endpoint<Peer>() {

Expand All @@ -36,22 +40,25 @@ class UtpEndpoint(
private val sendBuffer = ByteBuffer.allocate(BUFFER_SIZE)
private val receiveBuffer = ByteBuffer.allocate(BUFFER_SIZE)

private var serverSocket: UtpServerSocketChannel? = null;
private var serverSocket: CustomUtpServerSocket? = null;
private var clientSocket: CustomUtpClientSocket? = null;

init {
UtpAlgConfiguration.MAX_CWND_INCREASE_PACKETS_PER_RTT = 3000
logger.error { "THIS IS UTP HERE!!!" }
}


override fun isOpen(): Boolean {
return serverSocket != null
return serverSocket != null && clientSocket != null
}

override fun send(peer: Peer, data: ByteArray) {
// Modify the address to use the open UTP port
// ???
send(peer, 13377, data)
}

send(IPv4Address(peer.wanAddress.ip, 13377), data)
fun send(peer: Peer, port: Int = 13377, data: ByteArray) {
send(IPv4Address(peer.address.ip, port), data)
}

fun send(ipv4Address: IPv4Address, data: ByteArray) {
Expand All @@ -61,25 +68,42 @@ class UtpEndpoint(
sendBuffer.put(data)

scope.launch(Dispatchers.IO) {
UtpSocketChannel.open().let { channel ->
val future = channel.connect(InetSocketAddress(ipv4Address.ip, ipv4Address.port))
?.apply { block() }
if (future != null) {
if (future.isSuccessfull) {
channel.write(sendBuffer)?.apply { block() }
logger.debug("Sent buffer")
} else logger.debug("Did not manage to connect to the server!")
} else {
logger.debug("Future is null!")
}
channel.close()
val future = clientSocket?.connect(InetSocketAddress(ipv4Address.ip, ipv4Address.port))
?.apply { block() }
if (future != null) {
if (future.isSuccessfull) {
clientSocket?.write(sendBuffer)?.apply { block() }
logger.debug("Sent buffer")
} else logger.debug("Did not manage to connect to the server!")
} else {
logger.debug("Future is null!")
}
}
}

fun sendRawClientData(packet: DatagramPacket) {
scope.launch(Dispatchers.IO) {
clientSocket?.sendRawData(packet)
}
}

fun sendServerData(packet: DatagramPacket) {
serverSocket?.sendData(packet)
}

override fun open() {
serverSocket = UtpServerSocketChannel.open()
serverSocket = CustomUtpServerSocket()
serverSocket?.bind(InetSocketAddress(ip, port))

val c = CustomUtpClientSocket()
try {
c.dgSocket = DatagramSocket()
c.state = UtpSocketState.CLOSED
} catch (exp: IOException) {
throw IOException("Could not open UtpSocketChannel: " + exp.message)
}
clientSocket = c

logger.debug("Server started on $ip:$port")
serverListen()
}
Expand All @@ -88,6 +112,7 @@ class UtpEndpoint(
logger.debug("Stopping the server!")
listenerJob.cancel()
serverSocket?.close()
clientSocket?.close()
}

private fun serverListen() {
Expand Down Expand Up @@ -119,4 +144,18 @@ class UtpEndpoint(
const val BUFFER_SIZE = 50_000_000
}

class CustomUtpServerSocket : UtpServerSocketChannelImpl() {
fun sendData(packet: DatagramPacket) {
socket.send(packet)
}

}

class CustomUtpClientSocket : UtpSocketChannelImpl() {

fun sendRawData(packet: DatagramPacket) {
dgSocket.send(packet)
}
}

}