-
Notifications
You must be signed in to change notification settings - Fork 293
relay/circuit-v2: Mark Reservation::expire as required #384
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
Conversation
The Go implementation of the circuit relay v2 implementation treats the
`Reservation::expire` field as `required`:
``` Golang
result := &Reservation{}
result.Expiration = time.Unix(int64(rsvp.GetExpire()), 0)
if result.Expiration.Before(time.Now()) {
return nil, fmt.Errorf("received reservation with expiration date in the past: %s", result.Expiration)
}
```
https://github.com/libp2p/go-libp2p/blob/bfee9f593553b3cdaecc351f04b98aac78b8d8af/p2p/protocol/circuitv2/client/reservation.go#L88-L92
Where `rsvp.GetExpire` returns `0` when `Reservation::expire` is not set:
``` Golang
func (m *Reservation) GetExpire() uint64 {
if m != nil && m.Expire != nil {
return *m.Expire
}
return 0
}
```
https://github.com/libp2p/go-libp2p/blob/bfee9f593553b3cdaecc351f04b98aac78b8d8af/p2p/protocol/circuitv2/pb/circuit.pb.go#L414-L419
While inexplicable to me why Go treats the non-set case equal to the default
value (`0`), we unfortunately have to take the go implementation as the source
of truth, given that it is already released.
With the above in mind and to prevent confusion for other implementations in
languages which do not treat the non-set case equal to the default value (`0`),
this commit marks the `Reservation::expire` field as `required`.
marten-seemann
left a comment
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.
We probably should have said that no expiration time means that it doesn't expire, but that ship has sailed.
|
How should we proceed with the message Limit {
optional uint32 duration = 1; // seconds
optional uint64 data = 2; // bytes
}func (m *Limit) GetDuration() uint32 {
if m != nil && m.Duration != nil {
return *m.Duration
}
return 0
}func (m *Limit) GetData() uint64 {
if m != nil && m.Data != nil {
return *m.Data
}
return 0
}How should we treat the-Golang-Protobuf-Compiler-Treating-Nil-and-Default-of-base-types-the-same more generally @marten-seemann @vyzo? Is there an alternative compiler go-libp2p could use? |
See libp2p/specs#384 for corresponding specification change.
|
I don't see any problem here. If you care about the distinction, just do a |
|
they are both truly optional i think, so we shouldnt maul them. |
So according to the Protobuf definition a limit with a limit := msg.GetLimit()
if limit != nil {
result.LimitDuration = time.Duration(limit.GetDuration()) * time.Second
result.LimitData = limit.GetData()
}
@vyzo I am not following. Could you paraphrase the above? |
|
i meant that either limit could be unset, and a value of 0 is meaningless so i dont see a problem with treating it is unset. |
The Go implementation of the circuit relay v2 implementation treats the
Reservation::expirefield asrequired:https://github.com/libp2p/go-libp2p/blob/bfee9f593553b3cdaecc351f04b98aac78b8d8af/p2p/protocol/circuitv2/client/reservation.go#L88-L92
Where
rsvp.GetExpirereturns0whenReservation::expireis not set:https://github.com/libp2p/go-libp2p/blob/bfee9f593553b3cdaecc351f04b98aac78b8d8af/p2p/protocol/circuitv2/pb/circuit.pb.go#L414-L419
While inexplicable to me why Go treats the non-set case equal to the default
value (
0), we unfortunately have to take the go implementation as the sourceof truth, given that it is already released.
With the above in mind and to prevent confusion for other implementations in
languages which do not treat the non-set case equal to the default value (
0),this commit marks the
Reservation::expirefield asrequired.What do folks think? If I am not mistaken, the change below is non-breaking
for the Go implementation, given that it effectlively already treats
expireasrequired.