hyperledger-archives / aries-framework-go

Hyperledger Aries Framework Go provides packages for building Agent / DIDComm services.
https://wiki.hyperledger.org/display/ARIES/aries-framework-go
Apache License 2.0
238 stars 159 forks source link

Cannot establish connection between two agents without inbound #2520

Open llbartekll opened 3 years ago

llbartekll commented 3 years ago

I have two mobile agents A and B and mediator agent M. Mobile agents configuration:

        opts?.addOutboundTransport("ws")
        opts?.transportReturnRoute = "all"
        opts?.autoAccept = true
  1. Mobile agents A and B register agent M as a router

  2. agents A creates an invitation:

    "invitation":{
      "service":[
         {
            "ID":"75fa5b47-e047-4d03-bbd0-a0a4074f305b",
            "Priority":0,
            "Type":"did-communication",
            "RecipientKeys":[
               "3P9DzAQ4VaPgy9VdbPCWJ65Yrxgyxi26urfHoGENyCC5"
            ],
            "ServiceEndpoint":"ws://3.122.231.249:8002",
            "RoutingKeys":[
               "GF2CwK3eAQZdUG5YxhJtsv7iGCFFavgbxQmBR5VcL7tv"
            ]
         }
      ],
      "label":"AgentA",
      "protocols":[
         "ws"
      ],
      "@type":"https://didcomm.org/oob-invitation/1.0/invitation",
      "@id":"2adcf178-169e-4b63-a66c-7e0db372a750"
    }
    }
  3. Agent B accept an invitation:

      "service":[
         {
            "ID":"75fa5b47-e047-4d03-bbd0-a0a4074f305b",
            "Priority":0,
            "Type":"did-communication",
            "RecipientKeys":[
               "3P9DzAQ4VaPgy9VdbPCWJ65Yrxgyxi26urfHoGENyCC5"
            ],
            "ServiceEndpoint":"ws://3.122.231.249:8002",
            "RoutingKeys":[
               "GF2CwK3eAQZdUG5YxhJtsv7iGCFFavgbxQmBR5VcL7tv"
            ]
         }
      ],
      "label":"AgetnA",
      "protocols":[
         "ws"
      ],
      "@type":"https://didcomm.org/oob-invitation/1.0/invitation",
      "@id":"2adcf178-169e-4b63-a66c-7e0db372a750"
    },
    "router_connections":"503f4136-b445-41ec-802b-bd79ecbf206b",
    "my_label":"AgentB"
    }
  4. Agent A gets status responded

  5. Agent B gets status completed

  6. Agent A is able to request presentation or propose credentials to agent B

  7. Agent B cannot respond to agent A and an error is thrown:

[aries-framework/did-exchange/service] 2021/02/08 09:53:02 UTC - n/a -> ERROR command=[didexchange] action=[processMessage] [msgType=[https://didcomm.org/didexchange/1.0/response] msgID=[f24ebfce-dee7-476c-8b7c-9aba5c39243e] connectionID=[f3dbbbc3-898c-4458-b34c-044cb595e570]] errMsg=[failed to execute state action 'completed': outboundDispatcher.Send: no transport found for serviceEndpoint: didcomm:transport/queue]

papkie commented 3 years ago

I have checked this issue and it seems there is a problem with passing the router key?

Configuration: Every agent is running with rest. Alice - outbound only, WebSocket, auto-accept Carl - outbound only, WebSocket, auto-accept Router - in/out, WebSocket, auto-accept

Steps I did to recreate this issue, using WebSocket:

  1. Create an invitation for Alice on Router
  2. Receive Router's invitation on Alice - connection has status complete
  3. Register Router as a mediator on Alice
  4. Create an invitation for Carl on Router
  5. Receive Router's invitation on Alice - connection has status complete
  6. Register Router as a mediator on Carl
  7. Create OOB invitation on Alice with router_connection_id of Router in body
  8. Receive OOB invitation on Carl with router_connection_id of Router in body
  9. Carl gets requested status in connection
  10. Alice gets abandoned Same issue for regular invitation/receive.

Alice throws this error:

 [aries-framework/out-of-band/service] 2021/02/10 13:10:40 UTC - outofband.(*Service).handleDIDEvent -> DEBUG input: {ProtocolName:didexchange Type:1 StateID:abandoned Msg:map[@id:f02db974-1ae4-4fbf-84d9-3ba1eee6c4cc @type:https://didcomm.org/didexchange/1.0/request _internal_metadata:map[] connection:map[did:did:peer:1zQmNyXoRZTr7ojWmMCoN2BmXFRffYfzDpqhnZFuNJKyciwX did_doc:map[@context:[https://w3id.org/did/v1] assertionMethod:[#1flj933qjuuidrs1yo21yzp2s9SisD-sCWmm4w6U6h0] authentication:[#1flj933qjuuidrs1yo21yzp2s9SisD-sCWmm4w6U6h0] created:2021-02-10T14:10:40.344195+01:00 id:did:peer:1zQmNyXoRZTr7ojWmMCoN2BmXFRffYfzDpqhnZFuNJKyciwX service:[map[id:d0df515b-7cce-4728-8fff-533d9b2a68f0 priority:0 recipientKeys:[GJGRfccvpaRSjJkBuF2YznJ4dB88huPV7Kx4UgbKyBmz] routingKeys:[] serviceEndpoint:didcomm:transport/queue type:did-communication]] updated:2021-02-10T14:10:40.344195+01:00 verificationMethod:[map[controller: id:#1flj933qjuuidrs1yo21yzp2s9SisD-sCWmm4w6U6h0 publicKeyBase58:GJGRfccvpaRSjJkBuF2YznJ4dB88huPV7Kx4UgbKyBmz type:Ed25519VerificationKey2018]]]] label:alice2 ~thread:map[pthid:7dcc1acf-b731-42d3-8443-7d297c7c594a thid:f02db974-1ae4-4fbf-84d9-3ba1eee6c4cc]] Properties:failed to execute state action 'responded': outboundDispatcher.Send: no transport found for serviceEndpoint: didcomm:transport/queue}

It looks like accepting requests does not get valid serviceEndpoint, so it does not know it should respond to Router with the given routing key.

It does work without the auto-accept flag enabled. Is it expected behavior?

soluchok commented 3 years ago

@llbartekll @papkie auto-accept is a helper function that accepts all actions related to didexchange without providing any arguments Continue(&Empty{}).

// the function body
for msg := range ch {
    msg.Continue(&Empty{})
}

In your case because of auto-accept you are missing the AcceptExchangeRequest call. exchange request was executed automatically. And the problem here is that router_connection_id was not provided due to (msg.Continue(&Empty{})).

The solution is to turn off auto-accept and perform A.AcceptExchangeRequest manually where you would need to provide a router_connection_id.

@papkie Is it expected behavior? - yes, it is.