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

Trustchain fails when executed from CLI. #56

Open
KoningR opened this issue Nov 22, 2021 · 3 comments
Open

Trustchain fails when executed from CLI. #56

KoningR opened this issue Nov 22, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@KoningR
Copy link

KoningR commented Nov 22, 2021

The Trustchain functionality does not work at all when running from the command line. The tests do, however, pass. This is specifically due to this snippet in Community.kt:

scope = CoroutineScope(Dispatchers.Main + job)

The Main dispatcher is meant to interact with UI objects and as such would like an Android, JavaFX, or Swing dependency. This is of course undesirable when running from command line. When running from command line, the application crashes when functionality using the Main dispatcher is used, for instance when signing agreement blocks. The demo-jvm application is too rudimentary to pick up on this. The unit tests also do not find this because during testing, the Main dispatcher is set to be a TestCoroutineDispatcher (see BaseCommunityTest.kt) which does work without a GUI. Additionally, it is considered bad practice to hardcode your dispatchers.

How to reproduce

Replace startIpv8() in Application.kt with the following and run two instances of the application:

private fun startIpv8() {
    val myKey = JavaCryptoProvider.generateKey()
    val myPeer = Peer(myKey)
    val udpEndpoint = UdpEndpoint(8090, InetAddress.getByName("0.0.0.0"))
    val endpoint = EndpointAggregator(udpEndpoint, null)

    val config = IPv8Configuration(overlays = listOf(
        createDiscoveryCommunity(),
        createTrustChainCommunity(),
        createDemoCommunity()
    ), walkerInterval = 1.0)

    val ipv8 = IPv8(endpoint, config, myPeer)
    ipv8.start()

    val trustCom = ipv8.getOverlay<TrustChainCommunity>()!!
    val demoCom = ipv8.getOverlay<DemoCommunity>()!!

    trustCom.registerBlockSigner("trust_issue_block", object : BlockSigner {
        override fun onSignatureRequest(block: TrustChainBlock) {
            logger.info("Received an issue block.")
            trustCom.createAgreementBlock(block, mapOf<Any?, Any?>())
        }
    })

    scope.launch {
        while (true) {
            if (demoCom.getPeers().isNotEmpty()) {
                trustCom.createProposalBlock(
                    "trust_issue_block",
                    mapOf("message" to "hi"),
                    demoCom.getPeers()[0].publicKey.keyToBin()
                )
            }

            for ((_, overlay) in ipv8.overlays) {
                printPeersInfo(overlay)
            }
            logger.info("===")
            delay(5000)
        }
    }

    while (ipv8.isStarted()) {
        Thread.sleep(1000)
    }
}
@synctext
Copy link
Member

Excellent work of making this Kotlin repo better!

@niyid
Copy link

niyid commented Nov 16, 2022

Hello All,

I wonder if anybody here has documentation or suggestions on how to get to speed with using this framework. Or is there a forum or chat channel where developers gather?

More specific question is: can this framework be used to create a tree of peers where getting reference to a peer will also provide reference to a list of nearby peers?

@InvictusRMC
Copy link
Member

@niyid I can advise you to have a look at the Python documentation.

@InvictusRMC InvictusRMC added the bug Something isn't working label Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants