id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c24400
o.MaxReconnectInterval = t return o }
c24401
o.AutoReconnect = a return o }
c24402
o.MessageChannelDepth = s return o }
c24403
http.Header) *ClientOptions { o.HTTPHeaders = h return o }
c24404
if !timer.Stop() { <-timer.C } return true case <-timer.C: } return false }
c24405
defer s.m.RUnlock() return s.subResult }
c24406
len(r.options.Servers)) for i, u := range r.options.Servers { nu := *u s[i] = &nu } return s }
c24407
DEBUG.Println(STR, "memorystore initialized") }
c24408
if m == nil { CRITICAL.Println(STR, "memorystore get: message", mid, "not found") } else { DEBUG.Println(STR, "memorystore get: message", mid, "found") } return m }
c24409
WARN.Println(STR, "memorystore del: message", mid, "not found") } else { delete(store.messages, key) DEBUG.Println(STR, "memorystore del: message", mid, "was deleted") } }
c24410
c.msgRouter.addRoute(topic, callback) } }
c24411
:= atomic.LoadUint32(&c.status) switch { case status == connected: return true default: return false } }
c24412
type")) return token } if pub.Qos != 0 && pub.MessageID == 0 { pub.MessageID = c.getID(token) token.messageID = pub.MessageID } persistOutbound(c.persist, pub) if c.connectionStatus() == reconnecting { DEBUG.Println(CLI, "storing publish message (reconnecting), topic:", topic) } else { DEBUG.Println(C...
c24413
token.messageID = details.MessageID c.claimID(token, details.MessageID) DEBUG.Println(STR, fmt.Sprintf("loaded pending publish (%d)", details.MessageID)) DEBUG.Println(STR, details) c.obound <- &PacketAndToken{p: packet, t: token} default: ERROR.Println(STR, "invalid message type in store (dis...
c24414
ClientOptionsReader{options: &c.options} return r }
c24415
newP.TopicName = p.TopicName newP.Payload = p.Payload return newP }
c24416
directory: directory, opened: false, } return store }
c24417
create it if !exists(store.directory) { perms := os.FileMode(0770) merr := os.MkdirAll(store.directory, perms) chkerr(merr) } store.opened = true DEBUG.Println(STR, "store is opened at", store.directory) }
c24418
store.RUnlock() return store.all() }
c24419
defer store.Unlock() store.del(key) }
c24420
for _, key := range store.all() { store.del(key) } }
c24421
make(chan bool)} stop := router.stop return router, stop }
c24422
r.callback = callback return } } r.routes.PushBack(&route{topic: topic, callback: callback}) }
c24423
if e.Value.(*route).match(topic) { r.routes.Remove(e) return } } }
c24424
defer r.Unlock() r.defaultHandler = handler }
c24425
return nil, ErrConnectionClosed } ec := &EncodedConn{Conn: c, Enc: EncoderForType(encType)} if ec.Enc == nil { return nil, fmt.Errorf("no encoder registered for '%s'", encType) } return ec, nil }
c24426
defer encLock.Unlock() encMap[encType] = enc }
c24427
encLock.Unlock() return encMap[encType] }
c24428
return err } return c.Conn.publish(subject, _EMPTY_, b) }
c24429
numArgs == 0 { return nil, numArgs } return cbType.In(numArgs - 1), numArgs }
c24430
return c.subscribe(subject, _EMPTY_, cb) }
c24431
{ return c.subscribe(subject, queue, cb) }
c24432
}) } return } if argType.Kind() != reflect.Ptr { oPtr = reflect.Indirect(oPtr) } // Callback Arity switch numArgs { case 1: oV = []reflect.Value{oPtr} case 2: subV := reflect.ValueOf(m.Subject) oV = []reflect.Value{subV, oPtr} case 3: subV := reflect.ValueOf(m.Sub...
c24433
nc.ps.ma.subject = nc.ps.argBuf[:len(nc.ps.ma.subject)] if nc.ps.ma.reply != nil { nc.ps.ma.reply = nc.ps.argBuf[len(nc.ps.ma.subject):] } }
c24434
DefaultPingInterval, MaxPingsOut: DefaultMaxPingOut, SubChanLen: DefaultMaxChanLen, ReconnectBufSize: DefaultReconnectBufSize, DrainTimeout: DefaultDrainTimeout, } }
c24435
o.Name = name return nil } }
c24436
or parsing rootCA file: %v", err) } ok := pool.AppendCertsFromPEM(rootPEM) if !ok { return fmt.Errorf("nats: failed to parse root certificate from %q", f) } } if o.TLSConfig == nil { o.TLSConfig = &tls.Config{MinVersion: tls.VersionTLS12} } o.TLSConfig.RootCAs = pool o.Secure = true retu...
c24437
} cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0]) if err != nil { return fmt.Errorf("nats: error parsing client certificate: %v", err) } if o.TLSConfig == nil { o.TLSConfig = &tls.Config{MinVersion: tls.VersionTLS12} } o.TLSConfig.Certificates = []tls.Certificate{cert} o.Secure = true ...
c24438
o.ReconnectWait = t return nil } }
c24439
o.MaxReconnect = max return nil } }
c24440
o.MaxPingsOut = max return nil } }
c24441
o.ReconnectBufSize = size return nil } }
c24442
return func(o *Options) error { o.DisconnectedCB = cb return nil } }
c24443
o.ReconnectedCB = cb return nil } }
c24444
return func(o *Options) error { o.ClosedCB = cb return nil } }
c24445
return func(o *Options) error { o.DiscoveredServersCB = cb return nil } }
c24446
o.AsyncErrorCB = cb return nil } }
c24447
o.Password = password return nil } }
c24448
return ErrTokenAlreadySet } o.Token = token return nil } }
c24449
return ErrTokenAlreadySet } o.TokenHandler = cb return nil } }
c24450
{ keyFile = userOrChainedFile } sigCB := func(nonce []byte) ([]byte, error) { return sigHandler(nonce, keyFile) } return UserJWT(userCB, sigCB) }
c24451
{ return ErrUserButNoSigCB } o.UserJWT = userCB o.SignatureCB = sigCB return nil } }
c24452
o.Nkey = pubKey o.SignatureCB = sigCB if pubKey != "" && sigCB == nil { return ErrNkeyButNoSigCB } return nil } }
c24453
return func(o *Options) error { o.CustomDialer = dialer return nil } }
c24454
nc.mu.Lock() defer nc.mu.Unlock() nc.Opts.DisconnectedCB = dcb }
c24455
nc.mu.Lock() defer nc.mu.Unlock() nc.Opts.ReconnectedCB = rcb }
c24456
nc.mu.Lock() defer nc.mu.Unlock() nc.Opts.DiscoveredServersCB = dscb }
c24457
nc.mu.Lock() defer nc.mu.Unlock() nc.Opts.ClosedCB = cb }
c24458
defer nc.mu.Unlock() nc.Opts.AsyncErrorCB = cb }
c24459
urls[i] = strings.TrimSpace(s) } return urls }
c24460
== nil { nc.Opts.Dialer = &net.Dialer{ Timeout: nc.Opts.Timeout, } } if err := nc.setupServerPool(); err != nil { return nil, err } // Create the async callback handler. nc.ach = &asyncCallbacksHandler{} nc.ach.cond = sync.NewCond(&nc.ach.mu) if err := nc.connect(); err != nil { return nil, err }...
c24461
s == nc.current { return i, s } } return -1, nil }
c24462
} else { nc.srvPool = sp[0 : num-1] } if len(nc.srvPool) <= 0 { nc.current = nil return nil, ErrNoServers } nc.current = nc.srvPool[0] return nc.srvPool[0], nil }
c24463
} for _, s := range nc.srvPool { if s != nil { nc.current = s return nil } } return ErrNoServers }
c24464
} else if len(nc.srvPool) <= 0 { // Place default URL if pool is empty. if err := nc.addURLToPool(DefaultURL, false, false); err != nil { return err } } // Check for Scheme hint to move to TLS mode. for _, srv := range nc.srvPool { if srv.url.Scheme == tlsScheme { // FIXME(dlc), this is for all in t...
c24465
= curl.User } // We are checking to see if we have a secure connection and are // adding an implicit server that just has an IP. If so we will remember // the current hostname we are connected to. if saveTLSName && hostIsIP(u) { tlsName = curl.Hostname() } } s := &srv{url: u, isImplicit: implicit, tl...
c24466
r := rand.New(source) for i := range nc.srvPool { j := r.Intn(i + 1) nc.srvPool[i], nc.srvPool[j] = nc.srvPool[j], nc.srvPool[i] } }
c24467
!nc.Opts.NoRandomize { rand.Shuffle(len(hosts), func(i, j int) { hosts[i], hosts[j] = hosts[j], hosts[i] }) } for _, host := range hosts { nc.conn, err = dialer.Dial("tcp", host) if err == nil { break } } if err != nil { return err } // No clue why, but this stalls and kills performance on Mac...
c24468
net.SplitHostPort(nc.current.url.Host) tlsCopy.ServerName = h } } nc.conn = tls.Client(nc.conn, tlsCopy) conn := nc.conn.(*tls.Conn) if err := conn.Handshake(); err != nil { return err } nc.bw = nc.newBuffer() return nil }
c24469
defer nc.mu.RUnlock() if nc.status != CONNECTED { return _EMPTY_ } return nc.current.url.String() }
c24470
{ return _EMPTY_ } return nc.conn.RemoteAddr().String() }
c24471
if nc.status != CONNECTED { return _EMPTY_ } return nc.info.Id }
c24472
// Setup scratch outbound buffer for PUB pub := nc.scratch[:len(_PUB_P_)] copy(pub, _PUB_P_) }
c24473
PING protocol. // Wait for the PONG response (or any error that we get from the server). err = nc.sendConnect() if err != nil { return err } // Reset the number of PING sent out nc.pout = 0 // Start or reset Timer if nc.Opts.PingInterval > 0 { if nc.ptmr == nil { nc.ptmr = time.AfterFunc(nc.Opts.PingI...
c24474
nc.close(DISCONNECTED, false) nc.mu.Lock() nc.current = nil } } else { // Cancel out default connection refused, will trigger the // No servers error conditional if strings.Contains(err.Error(), "connection refused") { returnedErr = nil } } } nc.initc = false if returnedErr == nil ...
c24475
TLS. o.Secure = true } // Need to rewrap with bufio if o.Secure { if err := nc.makeTLSConn(); err != nil { return err } } return nil }
c24476
the protocol if err := nc.processInfo(c.args); err != nil { return err } if nc.Opts.Nkey != "" && nc.info.Nonce == "" { return ErrNkeysNotSupported } return nc.checkForSecure() }
c24477
nc.kickFlusher() nc.mu.Unlock() }
c24478
strings.TrimLeft(strings.TrimRight(s, "'"), "'") return s }
c24479
if err == io.EOF { return string(buf), nil } return "", err } buf = append(buf, b[0]) if b[0] == protoEnd { return string(buf), nil } } }
c24480
line, err := br.ReadString('\n') if err != nil { return err } parseControl(line, c) return nil }
c24481
c.args = _EMPTY_ } else if len(toks) == 2 { c.op, c.args = strings.TrimSpace(toks[0]), strings.TrimSpace(toks[1]) } else { c.op = _EMPTY_ } }
c24482
if nc.pending.Len() > 0 { nc.bw.Write(nc.pending.Bytes()) } }
c24483
nc.mu.Unlock() if sleepTime <= 0 { runtime.Gosched() } else { time.Sleep(time.Duration(sleepTime)) } // If the readLoop, etc.. go routines were started, wait for them to complete. if waitForGoRoutines { nc.waitForExits() waitForGoRoutines = false } nc.mu.Lock() // Check if we have been cl...
c24484
// Create pending buffer before reconnecting. nc.pending = new(bytes.Buffer) nc.bw.Reset(nc.pending) go nc.doReconnect() nc.mu.Unlock() return } nc.status = DISCONNECTED nc.err = err nc.mu.Unlock() nc.Close() }
c24485
ac.mu.Unlock() // This signals that the dispatcher has been closed and all // previous callbacks have been dispatched. if cur.f == nil { return } // Invoke callback outside of handler's lock cur.f() } }
c24486
the dispatcher that it should stop. if !close && f == nil { panic("pushing a nil callback") } cb := &asyncCB{f: f} if ac.tail != nil { ac.tail.next = cb } else { ac.head = cb } ac.tail = cb if close { ac.cond.Broadcast() } else { ac.cond.Signal() } }
c24487
if m.barrier != nil { s.mu.Unlock() if atomic.AddInt64(&m.barrier.refs, -1) == 0 { m.barrier.f() } continue } msgLen = len(m.Data) } mcb := s.mcb max = s.max closed = s.closed if !s.closed { s.delivered++ delivered = s.delivered } s.mu.Unlock() if closed { break ...
c24488
nc.Opts.AsyncErrorCB != nil { nc.ach.push(func() { nc.Opts.AsyncErrorCB(nc, nil, e) }) } nc.mu.Unlock() }
c24489
{ nc.Opts.AsyncErrorCB(nc, nil, ErrAuthorization) }) } nc.mu.Unlock() }
c24490
see if we should bail out. if !nc.isConnected() || nc.isConnecting() || bw != nc.bw || conn != nc.conn { nc.mu.Unlock() return } if bw.Buffered() > 0 { if err := bw.Flush(); err != nil { if nc.err == nil { nc.err = err } } } nc.mu.Unlock() } }
c24491
0 { ch = nc.pongs[0] nc.pongs = nc.pongs[1:] } nc.pout = 0 nc.mu.Unlock() if ch != nil { ch <- struct{}{} } }
c24492
|| srv.url == nc.current.url { continue } if !inInfo { // Remove from server pool. Keep current order. copy(sp[i:], sp[i+1:]) nc.srvPool = sp[:len(sp)-1] sp = nc.srvPool i-- } } // Figure out if we should save off the current non-IP hostname if we encounter a bare IP. saveTLS := nc.current !...
c24493
errors, we will simply not update the server pool... nc.processInfo(string(info)) nc.mu.Unlock() }
c24494
nc.mu.RLock() err := nc.err nc.mu.RUnlock() return err }
c24495
strings.HasPrefix(e, AUTHORIZATION_ERR) { nc.processAuthorizationViolation(ne) } else { nc.mu.Lock() nc.err = errors.New("nats: " + ne) nc.mu.Unlock() nc.Close() } }
c24496
return nc.publish(subj, _EMPTY_, data) }
c24497
nc.publish(m.Subject, m.Reply, m.Data) }
c24498
is ok, // just avoid strconv in fast path // FIXME(dlc) - Find a better way here. // msgh = strconv.AppendInt(msgh, int64(len(data)), 10) var b [12]byte var i = len(b) if len(data) > 0 { for l := len(data); l > 0; l /= 10 { i -= 1 b[i] = digits[l%10] } } else { i -= 1 b[i] = digits[0] } msgh =...
c24499
delete(nc.respMap, rt) nc.mu.Unlock() // Don't block, let Request timeout instead, mch is // buffered and we should delete the key before a // second response is processed. select { case mch <- m: default: return } }