2 // Copyright © 2016 Guy M. Allard
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 Package sngecomm provides common functionality used in the stompngo_examples
29 // "github.com/gmallard/stompngo"
34 nqs
= 1 // Default number of queues for multi-queue demo(s)
35 mdml
= 1024 * 32 // Message data max length of variable message, 32K
36 md
= make([]byte, 1) // Additional message data, primed during init()
37 pbc
= 64 // Number of bytes to print (used in some
38 // // examples that receive).
40 sendFact
float64 = 1.0 // Send sleep time factor
41 recvFact
float64 = 1.0 // Receive sleep time factor
43 ackMode
= "auto" // The default ack mode
45 pprof
= false // Do not do profiling
47 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC0,0x2F
48 // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC0,0x2B
49 // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC0,0x30
50 cipherSuites
= []uint16{
56 useCustomCiphers
= false // Set Custom Cipher Suite list
62 p
:= "_123456789ABCDEF"
65 md
= bytes
.Repeat(b
, c
) // A long string
72 if s
:= os
.Getenv("STOMP_NQS"); s
!= "" {
73 i
, e
:= strconv
.ParseInt(s
, 10, 32)
75 log
.Printf("v1:%v v2:%v\n", "NQS conversion error", e
)
83 // Max Data Message Length
85 if s
:= os
.Getenv("STOMP_MDML"); s
!= "" {
86 i
, e
:= strconv
.ParseInt(s
, 10, 32)
88 log
.Printf("v1:%v v2:%v\n", "MDML conversion error", e
)
91 p
:= "_123456789ABCDEF"
94 md
= bytes
.Repeat(b
, c
) // A long string
100 // Use profiling or not
102 if am
:= os
.Getenv("STOMP_PPROF"); am
!= "" {
108 // ACK mode for those examples that use it.
109 func AckMode() string {
110 if am
:= os
.Getenv("STOMP_ACKMODE"); am
!= "" {
111 if am
== "auto" || am
== "client" || am
== "client-individual" {
114 log
.Printf("v1:%v v2:%v\n", "ACKMODE error", am
)
120 // Get Send Sleep Factor
121 func SendFactor() float64 {
122 if s
:= os
.Getenv("STOMP_SENDFACT"); s
!= "" {
123 f
, e
:= strconv
.ParseFloat(s
, 64)
125 log
.Printf("v1:%v v2:%v\n", "SENDFACT conversion error", e
)
127 sendFact
= float64(f
)
133 // Get Recv Sleep Factor
134 func RecvFactor() float64 {
135 if s
:= os
.Getenv("STOMP_RECVFACT"); s
!= "" {
136 f
, e
:= strconv
.ParseFloat(s
, 64)
138 log
.Printf("v1:%v v2:%v\n", "RECVFACT conversion error", e
)
140 recvFact
= float64(f
)
146 // Get partial string, random length
147 func Partial() []byte {
148 r
:= int(ValueBetween(1, int64(mdml
-1), 1.0))
154 if s
:= os
.Getenv("STOMP_PBC"); s
!= "" {
155 i
, e
:= strconv
.ParseInt(s
, 10, 32)
157 log
.Printf("v1:%v v2:%v\n", "PBC conversion error", e
)
165 // Does receive wait to simulate message processing
166 func RecvWait() bool {
167 f
:= os
.Getenv("STOMP_RECVWAIT")
174 // Does send wait to simulate message building
175 func SendWait() bool {
176 f
:= os
.Getenv("STOMP_SENDWAIT")
183 // True if max procs are to be set
184 func SetMAXPROCS() bool {
185 f
:= os
.Getenv("STOMP_SETMAXPROCS")
192 // Use Custon Cipher List
193 func UseCustomCiphers() bool {
194 f
:= os
.Getenv("STOMP_USECUSTOMCIPHERS")
196 return useCustomCiphers
198 useCustomCiphers
= true
199 return useCustomCiphers
203 func CustomCiphers() []uint16 {
204 if UseCustomCiphers() {