(The conversation has gone off-list for the last couple of messages. Since this it has been resolved I'm sending this to the list too to let it known that it's done.)
"Schanzenbach, Martin" <[email protected]> writes: >> The misleading factor is that it's unclear when the ego (in this case >> the argument `e') is not valid anymore. >> > > Ah good catch. I rarely use ego_lookup. I usually connect to the identity > service and use the callback. See below why. > > >> Does the ego become invalid when the `ego_callback' function terminates? >> If so, how can I make a copy of the private key? Is `memcpy' enough or >> do I have to consider some other conditions? >> > > Yes, you can memcpy it. Or just assign it: > > mystruct.privkey = *eqk; > >> Another question is why does the private key have this property? Can't >> the function return a new allocated structure or fill one passed as >> argument, instead? >> > > The ego struct's lifetime is limited to the callback for lookup > functionality of identity. See identity_api_lookup.c::125 > > If you use "h = GNUNET_IDENTITY_connect (cfg, ego_cb);" > you will receive all current egos. You can store them in a list. > Those egos lifetime will be the same as the handle "h". So you > can use the keys until you disconnect (GNUNET_IDENTITY_disconnect(h)). > > If your program may use more than one ego, then the above is probably > better. See how, for example, identity/plugin_rest_identity.c is using it. > > BR I tried using `GNUNET_memcpy' to get a copy of the private key and in fact now it works, showing that the problem was indeed connected to the lifespan of the ego provided by `GNUNET_IDENTITY_ego_lookup'. Even though a part of the application does allow changing egos, in terms of changing code and testing, looking up a single ego and making a copy of the key takes less work and is already tested, so unless there happen to be special considerations to take I'm going to roll with it; I'll keep in mind the other method for when I need a better control over the lifespan of the egos returned by the identity service. Thank you for your time. A.V.
