From b4b6dc2b6b6be6c7d50a8f63f36413949b8d0ac9 Mon Sep 17 00:00:00 2001 From: d98762625 Date: Fri, 27 Mar 2020 12:55:46 +0000 Subject: [PATCH] Add ability to set capability on the terminus struct --- go/pkg/amqp/url_test.go | 8 -------- go/pkg/electron/link.go | 23 ++++++++++++++--------- go/pkg/electron/link_test.go | 6 +++--- go/pkg/proton/wrappers.go | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/go/pkg/amqp/url_test.go b/go/pkg/amqp/url_test.go index 192e2fb04e..281057d4e4 100644 --- a/go/pkg/amqp/url_test.go +++ b/go/pkg/amqp/url_test.go @@ -32,13 +32,6 @@ func ExampleParseURL() { "amqps://host", "/path", "", - ":1234", - // 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 { @@ -55,5 +48,4 @@ func ExampleParseURL() { // amqps://host:amqps // amqp://localhost:amqp/path // amqp://localhost:amqp - // parse :1234: missing protocol scheme } diff --git a/go/pkg/electron/link.go b/go/pkg/electron/link.go index 303f815b8f..eab151e205 100644 --- a/go/pkg/electron/link.go +++ b/go/pkg/electron/link.go @@ -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 @@ -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(), } } @@ -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)) diff --git a/go/pkg/electron/link_test.go b/go/pkg/electron/link_test.go index e6f1e2e9ff..46e490c81d 100644 --- a/go/pkg/electron/link_test.go +++ b/go/pkg/electron/link_test.go @@ -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) @@ -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())) } } diff --git a/go/pkg/proton/wrappers.go b/go/pkg/proton/wrappers.go index 724f6934b7..18be1612d6 100644 --- a/go/pkg/proton/wrappers.go +++ b/go/pkg/proton/wrappers.go @@ -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) + } +}