fanout/zurl

posting data example

Closed this issue · 6 comments

While reading the post example i have no idea how it works.

Why is this needed?
https://github.com/fanout/zurl/blob/master/tools/post.py#L39-L44
The only thing i see is the data being echoed back which is received
Same here: https://github.com/fanout/zurl/blob/master/tools/post.py#L48-L52
All i see is the seq counter is being increased while echoing the received data back, and in the case of the if 'body' in data and len(data['body']) > 0: line the body which just get send is also echoed back?

What are those credits?

Why isn't the first part of the file send in the initial push send here? https://github.com/fanout/zurl/blob/master/tools/post.py#L26

It's all a bit confusing.

Hi Asmod4n! Sorry for the confusion. The example code is a bit cryptic.

The keep-alive packet type is used to keep the session active even if there is no other activity. Zurl will send this packet every so often.

The example code sends keep-alive every so often as well, simply by reacting to received keep alives. This is actually bad practice but it was a simple hack to avoid having to keep track of time in the example.

Regarding credits and initial push, here's a quote from the spec: "Each side is assumed to start with 0 credits and should not send data unless they believe they have credits. Credits only apply to body data. As a special exception, the initiator may provide body data without having been granted any credits. It should assume it has 0 after this."

So you actually can send the first part of the request body in the first packet. If you do this, you should limit the size to Zurl's buffer_size (in zurl.conf).

Btw, post.py is for a streaming POST. If you have the entire request body and it is not too large, then you can use the much simpler REQ/REP interface as found in get.py. Just set req['method'] to POST and req['body'] to the body content.

have been reading the spec since then, cleared most of my confusion :)

What happens when i start a advanced session and set my credits to higher than the buffer_size?
Will i get a reply back which tells me how much i can send in credits?

You only grant credits to the other side. For example, if you send a credits field set to 500000, this means that the peer (e.g. Zurl) is allowed to send up to 500000 body bytes until you grant more credits. However, this says nothing about how much you are allowed to send to the peer. For that, you have to wait for the peer to grant you credits, which could be some completely different number.

Ah, thanks for the clarifications :)