Holochain Forum

Implementation node-to-node messaging

Where can I find source code that explains node-to-node messaging?

I’m trying to make nodes communicate privately in the background.
I found send function, but I have some ambiguity in the implementation and need answers for these questions :

  • How can I get parameters such as Agent Id and network status?
  • How can I receive the message?

Here’s a bit of info…


The ‘api’ section of the docs, relating to the HDK itself, will have better details on usage

1 Like

Yeh the explanation in API is much better. :+1:

Thank you so much @Connoropolous

Do you have any idea about traits : and its usage?
Is it mandatory for the success of communication?

I think that’s just marking the send_message function as a hc_public function so you can call it from outside the conductor.
You will need to have the agent’s id in order to send a message to them.
Each agent can get their own address with this https://developer.holochain.org/api/v0.0.32-alpha2/hdk/api/struct.agent_address
You might want to setup an anchor that links to all the agents names and their address like an index. Alternatively you can get an agents address from the first commit in there source chain.

I think it is much clearer now. :+1:

so that’s mean I either can get the agent address by:

  1. Struct hdk::api::AGENT_ADDRESS
    let to_agent: Address = AGENT_ADDRESS.to_string().into();
  2. link all agents addresses together, then retrieve them using get links function
    hdk::get_links(&base, "item_tag")
  3. returned value from commit function :
    let to_agent = hdk::commit_entry(&post_entry)?;

I’m not sure about the last one. hope you correct me if I misunderstand it.

Other question:

if I want to make the receiver do some actions when receiving my message. How can I do it?

Actually, I want the agent updates some data within its own local storage according to my message.


  1. for sure
  2. I think you could do this.
  3. This is the address of the entry that is returned.
    I think the agents address is held in the first entry. It really depends what you’re trying to do.
    If you have an entry from an agent and you want there address you can check the provenances and it’s the first signature. (I think that’s correct @pauldaoust ?)

This next question:
Thinking this through you can’t ever rely on another agent to do something on their end unless they can prove it to you some how.

I’m thinking they would need to commit an entry to prove that this has happened but it’s pretty hard to prove something is in a certain state outside of Holochain.
Can you give me a bit more of a use case?

Hi @freesig It is something like this:

a system that manages users’ profiles, where users gain scores according to their activity in the network. So, each user profile should be updated frequently as much as a user interacts with others.

I’m thinking to make each agent responsible for managing a group of users, compute their score based on opinions from others and do some checkings before committing data.

I think it is pretty difficult to make all agents participate in updating the same profile and its difficult to find the evaluator in case of fake scores.

I might be mis-understanding something here but could you no just make the users computer their own score and publish it to the dht so other agents can validate it.

Validating the other players would look something like you get another users score entry and then you rerun the entry through the validation rules. It if passes then you know they weren’t faking the score.

The trick here is finding an algorithm that you can run on any users entry in order to calculate the score.

Does that help or have I missed something?

The idea is each node acts as a master node for a group of people. So, the master node is the only one who’s responsible for managing profiles of people within its zone and update their data.

Other nodes can either read data from the master or pass a new score to tell the master to update this person.

For now, my concern is how can I make Node B tells Node A to update data about A: 003
Hope it is clear now thank you @freesig and sorry for bothering you

Hey @Rzan
Don’t be sorry at all, I love these conversations. I think they are very helpful to have and for others to read.

One thing you could do is create a message type call something like UpdateUser and then when it’s received the receive zome function could match on that message type and commit the update to the person.
You would need to have something in the validation code for the commit which updates the user to check that the user does belong to the node.

In this example:

  1. Node B messages Node A with an UpdateUser message for A:003.
  2. When Node A gets this message the receive callback is run and a new commit is made that updates A:003.
  3. The commit that updates A:003 has a check in validation that looks for a previous entry (Could also be a link) that shows Node A is the master to A:003.

You would also need to figure out some rules on how users get a master so that this is validated as well.

Hope that helps :smile:

It’s nice of you @freesig . I’m also enjoying while discussing things in the forum. It helps me in understanding since some parts of the documentation are not completed yet. Also, this GitHub project was very helpful https://github.com/holochain/peer-chat

I notice recently my problem is in receive callback . It works only when the agent sends a message to itself. I think the reason is in the version I’m using. So, I will update it and see.