Added version to user agent info, and other minor fixes

This commit is contained in:
2017-07-05 00:37:45 +02:00
parent 35d7486869
commit d3a06e7639
12 changed files with 69 additions and 14 deletions

View File

@ -75,6 +75,7 @@ class BitmessageContext(
},
listener: Listener,
labeler: Labeler = DefaultLabeler(),
userAgent: String? = null,
port: Int = 8444,
connectionTTL: Long = 30 * MINUTE,
connectionLimit: Int = 150,
@ -99,6 +100,7 @@ class BitmessageContext(
},
builder.listener,
builder.labeler ?: DefaultLabeler(),
builder.userAgent,
builder.port,
builder.connectionTTL,
builder.connectionLimit,
@ -333,6 +335,7 @@ class BitmessageContext(
fun status(): Property {
return Property("status",
Property("user agent", internals.userAgent),
internals.networkHandler.getNetworkStatus(),
Property("unacknowledged", internals.messageRepository.findMessagesToResend().size)
)
@ -361,6 +364,7 @@ class BitmessageContext(
internal var cryptography by Delegates.notNull<Cryptography>()
internal var customCommandHandler: CustomCommandHandler? = null
internal var labeler: Labeler? = null
internal var userAgent: String? = null
internal var listener by Delegates.notNull<Listener>()
internal var connectionLimit = 150
internal var connectionTTL = 30 * MINUTE
@ -480,6 +484,7 @@ class BitmessageContext(
customCommandHandler,
listener,
labeler,
userAgent?.let { "/$it/Jabit:$version/" } ?: "/Jabit:$version/",
port,
connectionTTL,
connectionLimit
@ -494,5 +499,11 @@ class BitmessageContext(
companion object {
@JvmField val CURRENT_VERSION = 3
private val LOG = LoggerFactory.getLogger(BitmessageContext::class.java)
val version: String by lazy {
BitmessageContext::class.java.getResource("/version")?.readText() ?: "local build"
}
@JvmStatic get
}
}

View File

@ -29,7 +29,7 @@ import ch.dissem.bitmessage.utils.Strings.hex
import org.slf4j.LoggerFactory
import java.util.*
internal open class DefaultMessageListener(
open class DefaultMessageListener(
private val labeler: Labeler,
private val listener: BitmessageContext.Listener
) : NetworkHandler.MessageListener, InternalContext.ContextHolder {

View File

@ -51,6 +51,8 @@ class InternalContext(
listener: BitmessageContext.Listener,
val labeler: Labeler,
val userAgent: String,
val port: Int,
val connectionTTL: Long,
val connectionLimit: Int

View File

@ -62,7 +62,7 @@ class Version constructor(
/**
* User Agent (0x00 if string is 0 bytes long). Sending nodes must not include a user_agent longer than 5000 bytes.
*/
val userAgent: String = "/Jabit:0.0.1/",
val userAgent: String,
/**
* The stream numbers that the emitting node is interested in. Sending nodes must not include more than 160000

View File

@ -25,7 +25,11 @@ package ch.dissem.bitmessage.utils
* If you need a real JSON representation, please add a method `toJson()`.
*
*/
class Property private constructor(val name: String, val value: Any? = null, val properties: Array<Property> = emptyArray()) {
class Property private constructor(
val name: String,
val value: Any? = null,
val properties: Array<Property>
) {
constructor(name: String, value: Any) : this(name = name, value = value, properties = emptyArray())
constructor(name: String, vararg properties: Property) : this(name, null, arrayOf(*properties))