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

Throw specialized exception when no suitable peers to broadcast outbound exception #196

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/main/kotlin/io/libp2p/pubsub/Errors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ class MessageAlreadySeenException(message: String) : PubsubException(message)
* Throw when message validation failed
*/
class InvalidMessageException(message: String) : PubsubException(message)

/**
* Thrown when no suitable peers found to broadcast outbound exception
*/
class NoPeersForOutboundMessageException(message: String) : PubsubException(message)
11 changes: 10 additions & 1 deletion src/main/kotlin/io/libp2p/pubsub/gossip/GossipRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.libp2p.core.InternalErrorException
import io.libp2p.core.PeerId
import io.libp2p.core.pubsub.ValidationResult
import io.libp2p.etc.types.anyComplete
import io.libp2p.etc.types.completedExceptionally
import io.libp2p.etc.types.copy
import io.libp2p.etc.types.createLRUMap
import io.libp2p.etc.types.median
Expand All @@ -14,6 +15,7 @@ import io.libp2p.etc.types.whenTrue
import io.libp2p.etc.util.P2PService
import io.libp2p.pubsub.AbstractRouter
import io.libp2p.pubsub.MessageId
import io.libp2p.pubsub.NoPeersForOutboundMessageException
import io.libp2p.pubsub.PubsubMessage
import io.libp2p.pubsub.PubsubProtocol
import io.libp2p.pubsub.SeenCache
Expand Down Expand Up @@ -360,7 +362,14 @@ open class GossipRouter @JvmOverloads constructor(

mCache += msg
flushAllPending()
return anyComplete(list)

if (list.isNotEmpty()) {
return anyComplete(list)
} else {
return completedExceptionally(
NoPeersForOutboundMessageException("No peers for message topics ${msg.topics} found")
)
}
}

override fun subscribe(topic: Topic) {
Expand Down