Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

You will lose an important tape file.


devel / comp.lang.ada / gnat -xdr flag confusion.

SubjectAuthor
* gnat -xdr flag confusion.magardner2010
`* Re: gnat -xdr flag confusion.Dmitry A. Kazakov
 `- Re: gnat -xdr flag confusion.magardner2010

1
gnat -xdr flag confusion.

<u80tsr$33eu$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9823&group=comp.lang.ada#9823

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: magardner2010@gmail.com (magardner2010)
Newsgroups: comp.lang.ada
Subject: gnat -xdr flag confusion.
Date: Tue, 4 Jul 2023 13:56:26 +0300
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <u80tsr$33eu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 4 Jul 2023 10:56:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8b58e21d8aa207bd5829e6e61f9e0d23";
logging-data="101854"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tMcdlOxeSQZQE0dz1PxHRVSGGoROuGoc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:tz+SJ4kSBFD7kINmNsRvFYUfZm0=
Content-Language: en-GB
 by: magardner2010 - Tue, 4 Jul 2023 10:56 UTC

I'm still working on the p2p one-to-many data streaming protocol thing
(at https://github.com/smeagolthellama/szakdolgozat-notes/tree/main/ada)
and I'm trying to get it to communicate with a C thing via the xdr
protocol. I'm trying to transfer a Child_Set, where
```
type Child_Number is range 0 .. 2;
subtype Child_Index is Child_Number range 1 .. Child_Number'Last;

type Child_Set is array (Child_Index) of GNAT.Sockets.Sock_Addr_Type;
```
With the help of chatGPT, I wrote the following xdr spec file:
```
const CHILD_NUMBER = 2;

typedef unsigned int uint32;
typedef unsigned char uint8;

enum family_type {
FAMILY_INET = 0,
FAMILY_INET6 = 1,
FAMILY_UNIX = 2,
FAMILY_UNSPEC = 3
};

union inet_addr_type switch (family_type family) {
case FAMILY_INET:
opaque sin_v4[4];
case FAMILY_INET6:
opaque sin_v6[16];
default:
void;
};

struct address_and_port{
inet_addr_type addr;
unsigned int port;
};

union sock_addr_type switch (family_type family) {
case FAMILY_UNIX:
string name<>;
case FAMILY_INET:
address_and_port anp4;
case FAMILY_INET6:
address_and_port anp6;
case FAMILY_UNSPEC:
void;
};

struct child_set {
sock_addr_type child_set_array[CHILD_NUMBER];
};
```
and using rpcgen, generated a C thing to encode/decode the messages the
ada program is sending.

However, if the ada code encodes the object with 'write, then it creates
something about 4 bytes too short, and if I use 'output, it is parsed as
starting with family_type 256, which is not a member of the enum. Given
that the gnat documentation for the -xdr flag is literally two lines, I
don't really know where to look for more information on what I'm doing
wrong. My current hypotheses include the C code having the family type
recorded too many times (but I don't know how to check or fix that in
the .x file) or the ada code not encoding the data according to the xdr
standard correctly (but I am using the flag, and neither 'write or
'output fixes it).

Re: gnat -xdr flag confusion.

<u810dh$12i2$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9824&group=comp.lang.ada#9824

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: gnat -xdr flag confusion.
Date: Tue, 4 Jul 2023 13:39:29 +0200
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <u810dh$12i2$1@dont-email.me>
References: <u80tsr$33eu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 4 Jul 2023 11:39:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="043ae2cbd5e9ab0720db7f7c64418928";
logging-data="35394"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183/QEq6xcyGDGgWz7CjgF0mDXD6zGVUhM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:PfKyl0STcu7RvHAImsKDYAnaHao=
In-Reply-To: <u80tsr$33eu$1@dont-email.me>
Content-Language: en-US
 by: Dmitry A. Kazakov - Tue, 4 Jul 2023 11:39 UTC

On 2023-07-04 12:56, magardner2010 wrote:

> However, if the ada code encodes the object with 'write, then it creates
> something about 4 bytes too short, and if I use 'output, it is parsed as
> starting with family_type 256, which is not a member of the enum. Given
> that the gnat documentation for the -xdr flag is literally two lines, I
> don't really know where to look for more information on what I'm doing
> wrong.

You never defined the protocol and implemented it in the first place.
You used some code generation tools which, if ever worked, will bite you
in the end.

To summarize the problem. The stream attribute 'Write writes the
constrained object. 'Output adds the constraints. Ada is capable to have
variable length records. C cannot do this. In short, it means that XDR's
discriminated union can be mapped onto Ada's variant record with no
default discriminant, but it cannot be directly mapped onto C's union. I
presume that GNAT implements XDR correctly and the C side does not cope.

Which is one of thousand reasons not to implement a communication
protocol by deriving representation from some language objects. Cutting
corners will not help you.

Define the (application level [*]) protocol. Implement it in Ada.
Implement it in C. Done.

---------------------
* XDR or ASN.1 or whatever are not application level!

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: gnat -xdr flag confusion.

<add91620-cdd4-d28f-1cbd-e07a473e707c@gmail.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9825&group=comp.lang.ada#9825

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: magardner2010@gmail.com (magardner2010)
Newsgroups: comp.lang.ada
Subject: Re: gnat -xdr flag confusion.
Date: Thu, 6 Jul 2023 20:32:10 +0300
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <add91620-cdd4-d28f-1cbd-e07a473e707c@gmail.com>
References: <u80tsr$33eu$1@dont-email.me> <u810dh$12i2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="a267ab58be88abdf36d6bce4afe3a1f0";
logging-data="1062531"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BUbFeXTV3xb9ZXCelwODNbYgGLP1lT/A="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:nz9R4zmzE0EO+KQmUD6nIh98Su4=
Content-Language: en-GB
In-Reply-To: <u810dh$12i2$1@dont-email.me>
 by: magardner2010 - Thu, 6 Jul 2023 17:32 UTC

On 04/07/2023 14:39, Dmitry A. Kazakov wrote:
> On 2023-07-04 12:56, magardner2010 wrote:
>
>> ...
>
> You never defined the protocol and implemented it in the first place.
> You used some code generation tools which, if ever worked, will bite you
> in the end.

With regards to the code generation tool (which I'm assuming refers to
chtGPT, for which I don't have enough creatively insulting backronyms),
I spent a good half a day getting the output to actually be accepted by
rpcgen. I then rewrote most of it from scratch.

With regards to the protocol implementation, I would like to point at
the function that begins at
https://github.com/smeagolthellama/szakdolgozat-notes/blob/f0b5143855f75354d41509845b0a41f0902d2928/ada/src/network_tree.adb#L29
, which has successfully communicated with other instances of itself,
albeit using 'write and 'read to handle anything more complicated than
"is the first character of the message a '?', a 'j', or a '>'?". My
question was about how to get C to understand the language Ada is
talking to itself in, given that that language should be at least
related to XDR.

>
> To summarize the problem. The stream attribute 'Write writes the
> constrained object. 'Output adds the constraints. Ada is capable to have
> variable length records. C cannot do this. In short, it means that XDR's
> discriminated union can be mapped onto Ada's variant record with no
> default discriminant, but it cannot be directly mapped onto C's union. I
> presume that GNAT implements XDR correctly and the C side does not cope.
>

I'm not sure I understand what you're saying here. Given that rpcgen
(which generates functions for xdr, as well as rpc, a superset thereof)
was a part of GNU's libc for a while, and still is on some ubuntu boxes,
along with the fact that a number of Linux's favourite protocols (such
as NFS) are implemented using it, I don't think the issue is the C side
implementing the encoder/decoder in a way that doesn't match my spec. I
expect either an Ada issue, a spec issue, or both.

> Which is one of thousand reasons not to implement a communication
> protocol by deriving representation from some language objects. Cutting
> corners will not help you.

I suppose there is wisdom in that, especially when attempting to
communicate across architectures, but I was working under the assumption
that the -xdr flag would remove the issue, as XDR is an
architecture-and-programming-language-agnostic data encoding/decoding
standard (or whatever an RFC counts as).

>
> Define the (application level [*]) protocol. Implement it in Ada.
> Implement it in C. Done.
>
> ---------------------
> *  XDR or ASN.1 or whatever are not application level!
>

I wouldn't have called XDR a protocol in the first place, except as a
simplification. I would like to use it as a *part* of my protocol, not
dissimilar to how NFS does, or programs that use G*ogle's protobuf thingie.

Specifically, when a peer receives a query (in the form of a message
starting with '?'), it should respond with a lump of data (current idea
is the Child_Set type from my previous post, encoded in the XDR format,
hence the difficulties) saying how many peers it has (in range 0..2),
and who they are (address-port combinations, where address can be IPv4
or 6), so that the querying party can find out if there is space for it
on this peer, or if it should look elsewhere. There are a couple of edge
cases, but this if you are curious you can look at my code.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor