-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare for handling uncompressed Gossip MessageId (#155)
* Initial refactor: replace Rpc.Message with abstract PubsubMessage which is created by pluggable messageFactory. messageFactory replaces messageIdGenerator because of PubsubMessage.messageId property * Convert messageId from String to byte[] (see spec PR: libp2p/specs#285) * Use WBytes ByteArray wrapper instead of plain ByteArray because of equals/hashCode absence * Replace AbstractRouter.seenMessages with a special SeenCache interface which is capable of handling PubsubMessage.messageId in a lazy fashion
- Loading branch information
1 parent
ec43a5b
commit eb0303a
Showing
25 changed files
with
920 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.libp2p.etc.types | ||
|
||
import com.google.protobuf.ByteString | ||
|
||
/** | ||
* `ByteArray` wrapper with `equals()`, `hashCode()` and `toString()` | ||
*/ | ||
class WBytes(val array: ByteArray) { | ||
|
||
operator fun plus(other: WBytes) = (array + other.array).toWBytes() | ||
operator fun plus(other: ByteArray) = (array + other).toWBytes() | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as WBytes | ||
|
||
if (!array.contentEquals(other.array)) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return array.contentHashCode() | ||
} | ||
|
||
override fun toString() = array.toHex() | ||
} | ||
|
||
fun ByteArray.toWBytes() = WBytes(this) | ||
fun String.toWBytes() = this.fromHex().toWBytes() | ||
fun WBytes.toProtobuf() = this.array.toProtobuf() | ||
fun ByteString.toWBytes() = this.toByteArray().toWBytes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
src/main/kotlin/io/libp2p/pubsub/PubsubMessageValidator.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.