Skip to content
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

PROTON-2202 [go] Add ability to set capability on the terminus struct #235

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions go/pkg/amqp/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ func ExampleParseURL() {
"amqps://host",
"/path",
"",
":1234",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this invalid case and the commented out ones, as per the comment on this PR

// Taken out because the go 1.4 URL parser isn't the same as later
//"[::1]",
//"[::1",
// Output would be:
// amqp://[::1]:amqp
// parse amqp://[::1: missing ']' in host
} {
u, err := ParseURL(s)
if err != nil {
Expand All @@ -55,5 +48,4 @@ func ExampleParseURL() {
// amqps://host:amqps
// amqp://localhost:amqp/path
// amqp://localhost:amqp
// parse :1234: missing protocol scheme
}
23 changes: 14 additions & 9 deletions go/pkg/electron/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ package electron

import (
"fmt"
"time"

"github.com/apache/qpid-proton/go/pkg/amqp"
"github.com/apache/qpid-proton/go/pkg/proton"
"time"
)

// Settings associated with a link
Expand Down Expand Up @@ -179,18 +180,20 @@ type linkSettings struct {
// Usually these can be set via a more descriptive LinkOption, e.g. DurableSubscription()
// and do not need to be set/examined directly.
type TerminusSettings struct {
Durability proton.Durability
Expiry proton.ExpiryPolicy
Timeout time.Duration
Dynamic bool
Durability proton.Durability
Expiry proton.ExpiryPolicy
Timeout time.Duration
Dynamic bool
Capabilities []string
}

func makeTerminusSettings(t proton.Terminus) TerminusSettings {
return TerminusSettings{
Durability: t.Durability(),
Expiry: t.ExpiryPolicy(),
Timeout: t.Timeout(),
Dynamic: t.IsDynamic(),
Durability: t.Durability(),
Expiry: t.ExpiryPolicy(),
Timeout: t.Timeout(),
Dynamic: t.IsDynamic(),
Capabilities: t.GetCapabilities(),
}
}

Expand Down Expand Up @@ -248,12 +251,14 @@ func makeLocalLink(sn *session, isSender bool, setting ...LinkOption) (linkSetti
l.pLink.Source().SetExpiryPolicy(l.sourceSettings.Expiry)
l.pLink.Source().SetTimeout(l.sourceSettings.Timeout)
l.pLink.Source().SetDynamic(l.sourceSettings.Dynamic)
l.pLink.Source().SetCapabilities(l.sourceSettings.Capabilities)

l.pLink.Target().SetAddress(l.target)
l.pLink.Target().SetDurability(l.targetSettings.Durability)
l.pLink.Target().SetExpiryPolicy(l.targetSettings.Expiry)
l.pLink.Target().SetTimeout(l.targetSettings.Timeout)
l.pLink.Target().SetDynamic(l.targetSettings.Dynamic)
l.pLink.Target().SetCapabilities(l.targetSettings.Capabilities)

l.pLink.SetSndSettleMode(proton.SndSettleMode(l.sndSettle))
l.pLink.SetRcvSettleMode(proton.RcvSettleMode(l.rcvSettle))
Expand Down
6 changes: 3 additions & 3 deletions go/pkg/electron/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
func TestLinkSettings(t *testing.T) {
cConn, sConn := net.Pipe()
done := make(chan error)
settings := TerminusSettings{Durability: 1, Expiry: 2, Timeout: 42 * time.Second, Dynamic: true}
settings := TerminusSettings{Durability: 1, Expiry: 2, Timeout: 42 * time.Second, Dynamic: true, Capabilities: []string{}}
filterMap := map[amqp.Symbol]interface{}{"int": int32(33), "str": "hello"}
go func() { // Server
close(done)
Expand All @@ -45,13 +45,13 @@ func TestLinkSettings(t *testing.T) {
switch ep := ep.(type) {
case Receiver:
test.ErrorIf(t, test.Differ("one.source", ep.Source()))
test.ErrorIf(t, test.Differ(TerminusSettings{}, ep.SourceSettings()))
test.ErrorIf(t, test.Differ(TerminusSettings{Capabilities: []string{}}, ep.SourceSettings()))
test.ErrorIf(t, test.Differ("one.target", ep.Target()))
test.ErrorIf(t, test.Differ(settings, ep.TargetSettings()))
case Sender:
test.ErrorIf(t, test.Differ("two", ep.LinkName()))
test.ErrorIf(t, test.Differ("two.source", ep.Source()))
test.ErrorIf(t, test.Differ(TerminusSettings{Durability: proton.Deliveries, Expiry: proton.ExpireNever}, ep.SourceSettings()))
test.ErrorIf(t, test.Differ(TerminusSettings{Durability: proton.Deliveries, Expiry: proton.ExpireNever, Capabilities: []string{}}, ep.SourceSettings()))
test.ErrorIf(t, test.Differ(filterMap, ep.Filter()))
}
}
Expand Down
32 changes: 32 additions & 0 deletions go/pkg/proton/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,35 @@ func (t Transport) SASL() SASL {
func SASLExtended() bool {
return bool(C.pn_sasl_extended())
}

// GetCapabilities returns the array of capabilities for the terminus
func (t Terminus) GetCapabilities() []string {
pn_data := C.pn_terminus_capabilities(t.pn)
size := int(C.pn_data_get_array(pn_data))
capabilities := make([]string, size, size)
if size > 0 {
C.pn_data_enter(pn_data)
for i := 0; i < size; i++ {
if C.pn_data_next(pn_data) {
csymbol := C.pn_data_get_symbol(pn_data)
symbol := C.GoString(csymbol.start)
capabilities = append(capabilities, symbol)
}
}
}
return capabilities
}

// SetCapabilities sets the array of capabilities for the terminus
func (t Terminus) SetCapabilities(capabilities []string) {
pn_data_t := C.pn_terminus_capabilities(t.pn)
C.pn_data_put_array(pn_data_t, false, C.PN_SYMBOL)
C.pn_data_enter(pn_data_t)
for _, capability := range capabilities {
capabilityCStr := C.CString(capability)
defer C.free(unsafe.Pointer(capabilityCStr))
capabilityCStrLen := C.size_t(len(capability))
capabilityCStrBytes := C.pn_bytes(capabilityCStrLen, capabilityCStr)
C.pn_data_put_symbol(pn_data_t, capabilityCStrBytes)
}
}