Re: Re: Re: Re: Re: Packet generalization

Hi Atul,

I’m glad you’re back with useful comments! I finally understood your point and attached is my interpretation of your idea. I still haven’t removed isValid but if all agree on the presented approach, I will do so with the next patch (I’ll need to do some modifications in the BitTorrent packets as well).

I thought it would be nice to make the packet factory a function object. That would be especially useful if we want to have a generic PacketReader class read any kind of binary packets as long as the necessary helpers are provided. These would be a functor to extract the raw data from the underlying Connection and another one to create the Packet object from the raw data.

Here are the modifications in Packet. I changed parse() to return bool and take the raw bytes as arguments. This would mean we don’t need the constructors taking raw bytes as parameters. If the new parse() returns false, that means that the raw data could not be parsed and a new object of type BadPacket is created from this raw data. If we return a singleton object, then we would not be able to dump the raw data and won’t be able to analyze whether the packet was really malformed or our implementation has a bug.

The patch also contains some minor modifications in fulfillment of the coding conventions. Most important are the new files BadPacket.{h|cpp} and PacketFactory.{h|cpp}.

What do you think of this solution, Atul? The others of you guys? Further suggestions?

Best regards,

Peter

P.S. Either check the patch, or pull my public bzr branch http://bzr.calitko.org/developers/peter/calitko-BitTorrent

atul wrote:

Hey Peter and everybody

Sorry for the late reply…

My idea was like this..

Packet factory would return a class which will be a wrapper for existing Packet… It will overload operator->() so delegates all the calls to the internal packet pointer…

Now here it could make a check for the validity of the packet and if the packet is not valid return a singleton packet pointer ( which is BadPacket ;-)

This way the check will never be missed and is guaranteed by design ;-)

—- cheers atul

Attached Files:

Would you like to post a relpy?


This post is a reply to:
Re: Re: Re: Re: Packet generalization
Hey Peter and everybody Sorry for the late reply... My idea was like this.. Packet factory would return a class which will be a wrapper for existing Packet... It will overload operator->() so (more...)

Follow-ups:
Re: Re: Re: Re: Re: Re: Packet generalization
Dear Peter I was not able to extract the patch on the source branch ... However I could read it fine... You have a great idea there and yes that is what (more...)