Simplified SettingsStore, it now uses it's own serializer
This commit is contained in:
parent
e08d5a3d2b
commit
b08b7a13cd
|
@ -385,7 +385,7 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
// we setup our kryo information once we connect to a server (using the server's kryo registration details)
|
// we setup our kryo information once we connect to a server (using the server's kryo registration details)
|
||||||
if (!serialization.finishInit(type, settingsStore, connectionInfo.kryoRegistrationDetails)) {
|
if (!serialization.finishInit(type, connectionInfo.kryoRegistrationDetails)) {
|
||||||
handshakeConnection.close()
|
handshakeConnection.close()
|
||||||
|
|
||||||
// because we are getting the class registration details from the SERVER, this should never be the case.
|
// because we are getting the class registration details from the SERVER, this should never be the case.
|
||||||
|
|
|
@ -143,7 +143,7 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
}
|
}
|
||||||
|
|
||||||
// we are done with initial configuration, now finish serialization
|
// we are done with initial configuration, now finish serialization
|
||||||
serialization.finishInit(type, settingsStore, ByteArray(0))
|
serialization.finishInit(type, ByteArray(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun newException(message: String, cause: Throwable?): Throwable {
|
override fun newException(message: String, cause: Throwable?): Throwable {
|
||||||
|
|
23
src/dorkbox/network/storage/Inet4AddressIpSerializer.kt
Normal file
23
src/dorkbox/network/storage/Inet4AddressIpSerializer.kt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package dorkbox.network.storage
|
||||||
|
|
||||||
|
import com.esotericsoftware.kryo.Kryo
|
||||||
|
import com.esotericsoftware.kryo.Serializer
|
||||||
|
import com.esotericsoftware.kryo.io.Input
|
||||||
|
import com.esotericsoftware.kryo.io.Output
|
||||||
|
import java.net.Inet4Address
|
||||||
|
import java.net.InetAddress
|
||||||
|
|
||||||
|
// NOTE: This only serializes the IP address, not the hostname!
|
||||||
|
class Inet4AddressIpSerializer : Serializer<Inet4Address>() {
|
||||||
|
init {
|
||||||
|
isImmutable = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun write(kryo: Kryo, output: Output, `object`: Inet4Address) {
|
||||||
|
output.write(`object`.address, 0, 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(kryo: Kryo, input: Input, type: Class<out Inet4Address>): Inet4Address {
|
||||||
|
return InetAddress.getByAddress("", input.readBytes(4)) as Inet4Address
|
||||||
|
}
|
||||||
|
}
|
29
src/dorkbox/network/storage/Inet6AddressIpSerializer.kt
Normal file
29
src/dorkbox/network/storage/Inet6AddressIpSerializer.kt
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package dorkbox.network.storage
|
||||||
|
|
||||||
|
import com.esotericsoftware.kryo.Kryo
|
||||||
|
import com.esotericsoftware.kryo.KryoException
|
||||||
|
import com.esotericsoftware.kryo.Serializer
|
||||||
|
import com.esotericsoftware.kryo.io.Input
|
||||||
|
import com.esotericsoftware.kryo.io.Output
|
||||||
|
import java.net.Inet6Address
|
||||||
|
import java.net.InetAddress
|
||||||
|
import java.net.UnknownHostException
|
||||||
|
|
||||||
|
// NOTE: This only serializes the IP address, not the hostname!
|
||||||
|
class Inet6AddressIpSerializer : Serializer<Inet6Address>() {
|
||||||
|
init {
|
||||||
|
isImmutable = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun write(kryo: Kryo, output: Output, `object`: Inet6Address) {
|
||||||
|
output.write(`object`.address, 0, 16)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(kryo: Kryo, input: Input, type: Class<out Inet6Address>): Inet6Address {
|
||||||
|
return try {
|
||||||
|
InetAddress.getByAddress("", input.readBytes(16)) as Inet6Address
|
||||||
|
} catch (e: UnknownHostException) {
|
||||||
|
throw KryoException(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package dorkbox.network.storage
|
package dorkbox.network.storage
|
||||||
|
|
||||||
|
import com.esotericsoftware.kryo.serializers.MapSerializer
|
||||||
import dorkbox.netUtil.IPv4
|
import dorkbox.netUtil.IPv4
|
||||||
import dorkbox.netUtil.IPv6
|
import dorkbox.netUtil.IPv6
|
||||||
import dorkbox.network.connection.CryptoManagement
|
import dorkbox.network.connection.CryptoManagement
|
||||||
|
@ -22,8 +23,11 @@ import dorkbox.util.bytes.ByteArrayWrapper
|
||||||
import dorkbox.util.exceptions.SecurityException
|
import dorkbox.util.exceptions.SecurityException
|
||||||
import dorkbox.util.storage.Storage
|
import dorkbox.util.storage.Storage
|
||||||
import dorkbox.util.storage.StorageBuilder
|
import dorkbox.util.storage.StorageBuilder
|
||||||
|
import dorkbox.util.storage.StorageSystem
|
||||||
import org.agrona.collections.Object2NullableObjectHashMap
|
import org.agrona.collections.Object2NullableObjectHashMap
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.net.Inet4Address
|
||||||
|
import java.net.Inet6Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
|
|
||||||
|
@ -48,6 +52,18 @@ open class SettingsStore(internal val builder: StorageBuilder) : AutoCloseable {
|
||||||
* Initialize using the provided serialization manager.
|
* Initialize using the provided serialization manager.
|
||||||
*/
|
*/
|
||||||
fun init() {
|
fun init() {
|
||||||
|
if (builder is StorageSystem.DiskBuilder) {
|
||||||
|
// NOTE: there are problems if our serializer is THE SAME serializer used by the network stack!
|
||||||
|
// make sure our custom types are registered!
|
||||||
|
builder.serializationManager.register(Object2NullableObjectHashMap::class.java, MapSerializer())
|
||||||
|
builder.serializationManager.register(ByteArrayWrapper::class.java)
|
||||||
|
builder.serializationManager.register(DB_Server::class.java)
|
||||||
|
|
||||||
|
// NOTE: These only serialize the IP address, not the hostname!
|
||||||
|
builder.serializationManager.register(Inet4Address::class.java, Inet4AddressIpSerializer())
|
||||||
|
builder.serializationManager.register(Inet6Address::class.java, Inet6AddressIpSerializer())
|
||||||
|
}
|
||||||
|
|
||||||
this.storage = builder.build()
|
this.storage = builder.build()
|
||||||
|
|
||||||
servers = this.storage.get(DB_Server.STORAGE_KEY, Object2NullableObjectHashMap())
|
servers = this.storage.get(DB_Server.STORAGE_KEY, Object2NullableObjectHashMap())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user