-
Notifications
You must be signed in to change notification settings - Fork 913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
connectd: add own err codes instead of generic -1 #3397
Conversation
1854cfb
to
214c38a
Compare
Ugly typecast is ugly. @rustyrussell opinion? |
214c38a
to
57fb2b3
Compare
We could add |
Largely agree as well. A bit more work but probably worth it for cleanliness. |
Agree, especially given that |
57fb2b3
to
e5fa911
Compare
I looked into this and realized there are two problems with
That said, I added a new commit e5fa911 that introduces Thoughts? |
While the Xref. (Though xref #3372 (comment)) 2s complement won and nobody in their right mind used sign-magnitude or 1s complement in the past two decades (IEEE 754 floats tho... but that was > three decades ago). Endianness is a bit iffier, though ultimately little-endian seems to be winning in the processor side (ARM is switching to it, and nobody uses anything but ARM or x86-derived anyway) while big-endian won on the network side (i.e. "network byte order" is big-endian). |
Make it possible for connectd to send an error code to lightningd in addition to the error message. Introduce two new error codes, replacing the catch-all -1. This change, together with ElementsProject#3395 will implement ElementsProject#3366 Changelog-Changed: The `connect` command now returns its own error codes instead of a generic -1.
Add towire_int() and fromwire_int() functions to "(de)serialize" "int". This will only work as long as both the caller of towire_int() and the caller of fromwire_int() use the same in-memory representation of signed integers and have the same sizeof(int). Changelog-None
e5fa911
to
732e790
Compare
@ZmnSCPxj I amended the last commit to add But I would really advise against that - it is a future trap for little or no justification (to avoid a typecast). Yes, all daemons currently run on the same machine, but thanks to the wire system it would be easy to move a given one on another machine and change stdout/stdin communication with a socket. Just that. But with such unportable towire_* functions one would also have to search for all of them and unroot them before moving a given daemon to a remote machine.
|
The original comment regarding |
Ok, so we have a few options:
|
if (!fromwire(cursor, max, &ret, sizeof(ret))) | ||
return 0; | ||
return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be missing an endianness conversion, be32_to_cpu
should do the trick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be32
assumes 32-bit int
s though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ZmnSCPxj would you prefer towire_s32() over towire_int()?
I am still most inclined to "Use the existent towire_u32()
for error codes (take just the first commit from this PR). We pass 400 and 401. Typecast to int
when calling command_fail()
because it takes an int
argument."
@@ -87,6 +87,11 @@ void towire_bool(u8 **pptr, bool v) | |||
towire(pptr, &val, sizeof(val)); | |||
} | |||
|
|||
void towire_int(u8 **pptr, int v) | |||
{ | |||
towire(pptr, &v, sizeof(v)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, cpu_to_be32
.
Since this PR is getting stuck with no good resolution, I'll just jump in and give what I think should be done:
If @vasild is willing to do that I can ACK that change so we can get some progress here. |
ACK 732e790 |
SGTM, I'll add a cleanup that just does the endiannes conversion, so we don't have this cornercase to keep in mind :-) ACK 732e790 |
Make it possible for connectd to send an error code to lightningd in
addition to the error message. Introduce two new error codes, replacing
the catch-all -1.
This change, together with
#3395
will implement #3366
Changelog-Changed: The
connect
command now returns its own error codes instead of a generic -1.