Skip to content

Commit

Permalink
Fix prefix/wildcard invocation handling (#137)
Browse files Browse the repository at this point in the history
* Fix handling of empty prefix matches for invocations

* Fix calls being continued when disclose was not allowed

* Provide procedure to wildcard clients
  • Loading branch information
martin31821 authored and gammazero committed Jul 27, 2018
1 parent 2d6ed6d commit 362c75b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion router/dealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (d *Dealer) matchProcedure(procedure wamp.URI) (*registration, bool) {
// No exact match was found. So, search for a prefix or wildcard
// match, and prefer the most specific math (longest matched pattern).
// If there is a tie, then prefer the first longest prefix.
var matchCount int
matchCount := -1 // initialize matchCount to -1 to catch an empty registration.
for pfxProc, pfxReg := range d.pfxProcRegMap {
if procedure.PrefixMatch(pfxProc) {
if len(pfxProc) > matchCount {
Expand All @@ -526,6 +526,12 @@ func (d *Dealer) matchProcedure(procedure wamp.URI) (*registration, bool) {
}
}
}
// according to the spec, we have to prefer prefix match over wildcard match:
// https://wamp-proto.org/static/rfc/draft-oberstet-hybi-crossbar-wamp.html#rfc.section.14.3.8.1.4.2
if ok {
return reg, ok
}

for wcProc, wcReg := range d.wcProcRegMap {
if procedure.WildcardMatch(wcProc) {
if len(wcProc) > matchCount {
Expand Down Expand Up @@ -621,6 +627,8 @@ func (d *Dealer) call(caller *session, msg *wamp.Call) {
Details: wamp.Dict{},
Error: wamp.ErrOptionDisallowedDiscloseMe,
})
// don't continue a call when discloseMe was disallowed.
return
}
if callee.HasFeature(roleCallee, featureCallerIdent) {
discloseCaller(caller, details)
Expand All @@ -639,6 +647,11 @@ func (d *Dealer) call(caller *session, msg *wamp.Call) {
}
}

if reg.match != wamp.MatchExact {
// according to the spec, a router has to provide the actual procedure to the client.
details[wamp.OptProcedure] = msg.Procedure
}

d.calls[msg.Request] = caller
invocationID := d.idGen.Next()
d.invocations[invocationID] = &invocation{
Expand Down
4 changes: 3 additions & 1 deletion router/dealer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,9 @@ func TestPatternBasedRegistration(t *testing.T) {
&wamp.Register{
Request: 123,
Procedure: testProcedureWC,
Options: wamp.Dict{"match": "wildcard"},
Options: wamp.Dict{
wamp.OptMatch: wamp.MatchWildcard,
},
})
rsp := <-callee.Recv()
_, ok := rsp.(*wamp.Registered)
Expand Down
1 change: 1 addition & 0 deletions wamp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
OptInvoke = "invoke"
OptMatch = "match"
OptMode = "mode"
OptProcedure = "procedure"
OptProgress = "progress"
OptReceiveProgress = "receive_progress"
OptTimeout = "timeout"
Expand Down

0 comments on commit 362c75b

Please sign in to comment.