0

I am connecting to an external VOLTTRON instance. I am not getting a response from the connection. What's the issue?

I am writing a simple python script to connect to an external platform and retrieve the peers. If I get the serverkey, clientkey, and/or publickey incorrect I don't know how to determine which is the culprit, from the client side. I just get a gevent timeout. Is there a way to know?

import os

import gevent
from volttron.platform.vip.agent import Agent

secret = "secret"
public = "public"
serverkey = "server"
tcp_address = "tcp://external:22916"

agent = Agent(address=tcp_address, serverkey=serverkey, secretkey=secret,
              publickey=public)
event = gevent.event.Event()
greenlet = gevent.spawn(agent.core.run, event)
event.wait(timeout=30)
print("My id: {}".format(agent.core.identity))
peers = agent.vip.peerlist().get(timeout=5)
for p in peers:
    print(p)
gevent.sleep(3)
greenlet.kill()
Craig
  • 949
  • 1
  • 5
  • 13

1 Answers1

2

The short answer: no, the client cannot determine why its connection to the server failed. The client will attempt to connect until it times out.

Logs and debug messages on the server side can help troubleshoot a connection problem. There are three distinct messages related to key errors:

  1. CURVE I: cannot open client HELLO -- wrong server key?
    Either the client omit the server key, the client used the wrong server key, or the server omit the secret key.

  2. CURVE I: cannot open client INITIATE vouch
    Either the client omit the public or secret key, or its public and secret keys don't correspond to each other.

  3. authentication failure
    The server key was correct and the secret and public keys are valid, but the server rejected the connection because the client was not authorized to connect (based on the client's public key).

The first two messages are printed by libzmq. To see the third message volttron must be started with increased verboseness (at least -v).


Here is a simple ZMQ server-client example you can use to test some of these scenarios:

Server:

import zmq 

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.curve_server = 1 
socket.curve_secretkey = "mW4i2O{kmcOXs9q>UP0(no4-Sp1r(p>vK?*NFwV$"
# The corresponding public key is "krEC0>hsx+o4Jxg2yvitCOVwr2GF85akNIsUdiH5"
socket.bind("ipc://test123")

while True:
    msg = socket.recv()
    new_msg = "I got the message: {}".format(msg)
    print(new_msg)
    socket.send(new_msg)

Client:

import zmq 

pub, sec = zmq.curve_keypair()
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.curve_secretkey = sec 
socket.curve_publickey = pub 
socket.curve_serverkey = "krEC0>hsx+o4Jxg2yvitCOVwr2GF85akNIsUdiH5"
socket.connect("ipc://test123")

socket.send(b'Hello')
msg = socket.recv()
print("From the server: {}".format(msg))
Zach
  • 36
  • 3
  • Which error in https://github.com/zeromq/pyzmq/blob/master/zmq/error.py would you think would CURVE I: cannot open client INITIATE vouch fall under, if any, since curve is so special. – Craig Nov 03 '16 at 16:28
  • @Craig: The error "CURVE I: cannot open client INITIATE vouch" does not generate an exception in pyzmq. I added example code in my answer so you can test out some scenarios if you'd like (e.g., comment out the client's public or secret key). – Zach Nov 03 '16 at 18:15
  • But what we truly need is that message to get back to the client some how rather than just being printed to standard error on the server. – Craig Nov 03 '16 at 19:20