Skip to content

Commit

Permalink
Add AdbServicesProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltak committed Apr 15, 2017
1 parent 7fc2912 commit c1ae053
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.eviltak.adbnmap.net.protocol

import java.net.Socket

/**
* The protocol used by the ADB client to communicate with the ADB server
*/
class AdbServicesProtocol(override val socket: Socket) : Protocol {

/**
* Send a test message in this communication protocol to a host through the [socket], eliciting a response
* from the target host confirming whether it supports this protocol or not.
*
* @param socket The socket connected to the host to which to send the test message.
*/
override fun sendTestMessage() {

}

/**
* Check if the host the [socket] is connected to uses this communication protocol.
*
* @param socket The socket connected to the host.
*
* @return true if the connected host uses this protocol, false otherwise.
*/
override fun hostUsesProtocol(): Boolean {
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class AdbTransportProtocol(override val socket: Socket) : Protocol {
/**
* Send a test message in this communication protocol to a host through the [socket], eliciting a response
* from the target host confirming whether it supports this protocol or not.
*
* @param socket The socket connected to the host to which to send the test message.
*/
override fun sendTestMessage() {
val outBuffer = ByteBuffer.allocate(4 * 6).order(ByteOrder.LITTLE_ENDIAN)
Expand All @@ -51,8 +49,6 @@ class AdbTransportProtocol(override val socket: Socket) : Protocol {
/**
* Check if the host the [socket] is connected to uses this communication protocol.
*
* @param socket The socket connected to the host.
*
* @return true if the connected host uses this protocol, false otherwise.
*/
override fun hostUsesProtocol(): Boolean {
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/net/eviltak/adbnmap/net/protocol/Protocol.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ import java.net.Socket
* A communication protocol that may be used by devices on a network.
*/
interface Protocol {
/**
* The socket connected to the target host.
*/
val socket: Socket

/**
* Send a test message in this communication protocol to a host through the [socket], eliciting a response
* from the target host confirming whether it supports this protocol or not.
*
* @param socket The socket connected to the host to which to send the test message.
*/
fun sendTestMessage()

/**
* Check if the host the [socket] is connected to uses this communication protocol. An implementation would
* ideally use [sendTestMessage] and listen for a valid response.
*
* @param socket The socket connected to the host.
*
* @return true if the connected host uses this protocol, false otherwise.
*/
fun hostUsesProtocol(): Boolean
Expand Down

0 comments on commit c1ae053

Please sign in to comment.