---
# System prepended metadata

title: P2P Communication DNA
tags: [Kizuna-architecture]

---

# P2P Communication DNA
###### tags: `Kizuna-architecture`
#### This document describes how a private communication DNA is generated using Conductor Admin Calls in Kizuna Messaging Application

## Dependency
- "Public/Lobby" DNA with request Zome

## DNA Instantiation Flow
- Same color means it is part of one graphql resolver
- Heavily dependent on a public DNA that has a request zome

```mermaid
sequenceDiagram
    rect rgb(0, 255, 0)
    Kizuna_UI_SENDER-->>P2P Comm DNA:1. Create P2PCommDNA with DNA Property (initializeP2PDNA)
    end
    
    rect rgb(0, 255, 0)
    Kizuna_UI_SENDER-->>P2P Comm DNA: 2. ensure that the agent was able to join the DNA
    end
    
    alt Failed to join DNA
    loop Until DNA joined
    rect rgb(0, 255, 0)
    Kizuna_UI_SENDER-->>P2P Comm DNA: 3. limitedly retry joining DNA
    end
    end
    end
    
    P2P Comm DNA-->>P2P Comm DNA: 4. validate_agent() check if the address of the agent is in members property
    
    Kizuna_UI_SENDER-->>Lobby_DNA_SENDER: 5. call request_to_chat zomeFunc in request zome
    
    Lobby_DNA_SENDER-->>Lobby_DNA_RECEIVER: 6. HDK::API::SEND to receiver agent in lobby DNA to request the receiver to join p2pDNA
        
    alt receiver online
        par 7.1
        Lobby_DNA_RECEIVER-->>Lobby_DNA_SENDER: receive callback: return request_received
        
        and 7.2
        Lobby_DNA_SENDER-->>Kizuna_UI_SENDER: return request_pending
        
        and 7.3
        Kizuna_UI_SENDER-->>Kizuna_UI_SENDER: render chat screen
        
        and 7.4
        alt sender exist in contact
        Lobby_DNA_RECEIVER-->>Kizuna_UI_RECEIVER: receive callback: emit_signal with in_contact: true
        
        else sender doesnt exist in contact
        Lobby_DNA_RECEIVER-->>Kizuna_UI_RECEIVER: receive callback: emit_signal with in_contact: false
        end
        
        and 7.5
        rect rgb(255,160,122)
        Kizuna_UI_RECEIVER-->>P2P Comm DNA: onSignal: join the DNA (joinChatResolver)
        end
        end
        
    else receiver offline
        par 7.1
        Lobby_DNA_RECEIVER-->>Lobby_DNA_SENDER: receive callback: return recipient_offline
        
        and 7.2
        Lobby_DNA_SENDER-->>Lobby_DNA_SENDER: commit request_notif entry and link it to receiver agent_address
        
        and 7.3
        Lobby_DNA_SENDER-->>Kizuna_UI_SENDER: return receiver_offline
        
        and 7.4
        Kizuna_UI_SENDER-->>Kizuna_UI_SENDER: render chat screen
        
        and 7.5
        Kizuna_UI_RECEIVER-->>Lobby_DNA_RECEIVER: call fetchRequestNotifs zomeFunc in request Zome when back online
        
        and 7.6
        rect rgb(255,160,122)
        Kizuna_UI_RECEIVER-->>P2P Comm DNA: join the DNA (joinChatResolver)
        end
        end
        end
    
        rect rgb(255,160,122)
        Kizuna_UI_RECEIVER-->>P2P Comm DNA: 8. ensure that the agent was able to join the DNA
        end
        
        alt Failed to join DNA
        loop Until DNA joined
        rect rgb(255,160,122)
        Kizuna_UI_RECEIVER-->>P2P Comm DNA: 9. limitedly retry joining DNA
        end
        end
        end
        
        P2P Comm DNA-->>P2P Comm DNA: 10. validate_agent()
        
        Kizuna_UI_RECEIVER-->>P2P Comm DNA: 11. getMessages()
        
        alt messages exist
        alt address in contact
        Kizuna_UI_RECEIVER-->>Kizuna_UI_RECEIVER: 12. render chat in messages page
        else address not in contact
        Kizuna_UI_RECEIVER-->>Kizuna_UI_RECEIVER: 12. render chat in messages request page
        end
        end
    
```
