id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c24500
return err } nc.mu.Lock() nc.respMux = s nc.mu.Unlock() return nil }
c24501
nc.respMap[token] = mch createSub := nc.respMux == nil ginbox := nc.respSub nc.mu.Unlock() if createSub { // Make sure scoped subscription is setup only once. var err error nc.respSetup.Do(func() { err = nc.createRespMux(ginbox) }) if err != nil { return nil, err } } if err := nc.PublishRequest(s...
c24502
ns := b[inboxPrefixLen:] copy(ns, nuid.Next()) return string(b[:]) }
c24503
NewInbox()) nc.respMap = make(map[string]chan *Msg) nc.respRand = rand.New(rand.NewSource(time.Now().UnixNano())) }
c24504
pres := b[:respInboxPrefixLen] copy(pres, nc.respSub) rn := nc.respRand.Int63() for i, l := respInboxPrefixLen, rn; i < len(b); i++ { b[i] = rdigits[l%base] l /= base } return string(b[:]) }
c24505
s := nc.newRespInbox() nc.mu.Unlock() return s }
c24506
return nc.subscribe(subj, queue, cb, nil, false) }
c24507
Subscription sub.typ = SyncSubscription sub.mch = ch } nc.subsMu.Lock() nc.ssid++ sub.sid = nc.ssid nc.subs[sub.sid] = sub nc.subsMu.Unlock() // We will send these for all subs when we reconnect // so that we can suppress here if reconnecting. if !nc.isReconnecting() { fmt.Fprintf(nc.bw, subProto, sub...
c24508
nc.mu.RUnlock() return len(nc.subs) }
c24509
close(s.mch) } s.mch = nil // Mark as invalid s.conn = nil s.closed = true if s.pCond != nil { s.pCond.Broadcast() } }
c24510
s.mu.Lock() defer s.mu.Unlock() return s.typ }
c24511
== nil { return ErrBadSubscription } return conn.unsubscribe(s, 0, true) }
c24512
s.mu.Unlock() if conn == nil { return ErrBadSubscription } if conn.IsDraining() { return ErrConnectionDraining } return conn.unsubscribe(s, 0, false) }
c24513
} // Check subscription state sub.mu.Lock() conn := sub.conn closed := sub.closed pMsgs := sub.pMsgs sub.mu.Unlock() if conn == nil || closed || pMsgs == 0 { nc.mu.Lock() nc.removeSub(sub) nc.mu.Unlock() return } time.Sleep(100 * time.Millisecond) } }
c24514
return ErrBadSubscription } return conn.unsubscribe(s, max, false) }
c24515
t := globalTimerPool.Get(timeout) defer globalTimerPool.Put(t) select { case msg, ok = <-mch: if !ok { return nil, ErrConnectionClosed } if err := s.processNextMsgDelivered(msg); err != nil { return nil, err } case <-t.C: return nil, ErrTimeout } return msg, nil }
c24516
return ErrBadSubscription } } if s.mcb != nil { return ErrSyncSubRequired } if s.sc { s.sc = false return ErrSlowConsumer } return nil }
c24517
// Remove subscription if we have reached max. if delivered == max { nc.mu.Lock() nc.removeSub(s) nc.mu.Unlock() } } return nil }
c24518
== ChanSubscription { return -1, -1, ErrTypeSubscription } return s.pMsgs, s.pBytes, nil }
c24519
== ChanSubscription { return -1, -1, ErrTypeSubscription } return s.pMsgsLimit, s.pBytesLimit, nil }
c24520
nc.bw.WriteString(pingProto) // Flush in place. nc.bw.Flush() }
c24521
nc.mu.Unlock() nc.processOpErr(ErrStaleConnection) return } nc.sendPing(nil) nc.ptmr.Reset(nc.Opts.PingInterval) nc.mu.Unlock() }
c24522
s.mu.Unlock() fmt.Fprintf(nc.bw, unsubProto, s.sid, _EMPTY_) continue } } s.mu.Unlock() fmt.Fprintf(nc.bw, subProto, s.Subject, s.Queue, s.sid) if adjustedMax > 0 { maxStr := strconv.Itoa(int(adjustedMax)) fmt.Fprintf(nc.bw, unsubProto, s.sid, maxStr) } } }
c24523
nc.pongs { if ch != nil { close(ch) } } nc.pongs = nil }
c24524
} for key, ch := range nc.respMap { if ch != nil { close(ch) delete(nc.respMap, key) } } }
c24525
// Mark connection closed in subscription s.connClosed = true // If we have an async subscription, signals it to exit if s.typ == AsyncSubscription && s.pCond != nil { s.pCond.Signal() } s.mu.Unlock() } nc.subs = nil nc.subsMu.Unlock() nc.status = status // Perform appropriate callback if needed f...
c24526
nc.mu.RUnlock() return nc.isClosed() }
c24527
nc.mu.RUnlock() return nc.isReconnecting() }
c24528
nc.mu.RUnlock() return nc.isConnected() }
c24529
} time.Sleep(10 * time.Millisecond) } // Check if we timed out. if nc.NumSubscriptions() != 0 { pushErr(ErrDrainTimeout) } // Flip State nc.mu.Lock() nc.status = DRAINING_PUBS nc.mu.Unlock() // Do publish drain via Flush() call. err := nc.Flush() if err != nil { pushErr(err) nc.Close() return ...
c24530
nc.mu.RUnlock() return nc.isDraining() }
c24531
url := nc.srvPool[i].url servers = append(servers, fmt.Sprintf("%s://%s", url.Scheme, url.Host)) } return servers }
c24532
nc.mu.RUnlock() return nc.getServers(false) }
c24533
nc.mu.RUnlock() return nc.getServers(true) }
c24534
nc.mu.RUnlock() return nc.status }
c24535
nc.status == DRAINING_SUBS || nc.status == DRAINING_PUBS }
c24536
nc.InBytes, OutMsgs: nc.OutMsgs, OutBytes: nc.OutBytes, Reconnects: nc.Reconnects, } nc.subsMu.RUnlock() nc.mu.Unlock() return stats }
c24537
nc.mu.RUnlock() return nc.info.MaxPayload }
c24538
nc.mu.RUnlock() return nc.info.AuthRequired }
c24539
nc.mu.RUnlock() return nc.info.TLSRequired }
c24540
if nc.info.CID == 0 { return 0, ErrClientIDNotSupported } return nc.info.CID, nil }
c24541
{ return nil, fmt.Errorf("nats: Not a valid nkey user seed") } sigCB := func(nonce []byte) ([]byte, error) { return sigHandler(nonce, seedFile) } return Nkey(string(pub), sigCB), nil }
c24542
on exit. defer kp.Wipe() sig, _ := kp.Sign(nonce) return sig, nil }
c24543
return &tls.Config{} } return c.Clone() }
c24544
{ err = nc.createRespMux(ginbox) }) if err != nil { return nil, err } } err := nc.PublishRequest(subj, respInbox, data) if err != nil { return nil, err } var ok bool var msg *Msg select { case msg, ok = <-mch: if !ok { return nil, ErrConnectionClosed } case <-ctx.Done(): nc.mu.Lock() de...
c24545
} s.AutoUnsubscribe(1) defer s.Unsubscribe() err = nc.PublishRequest(subj, inbox, data) if err != nil { return nil, err } return s.NextMsgWithContext(ctx) }
c24546
bool var msg *Msg // If something is available right away, let's optimize that case. select { case msg, ok = <-mch: if !ok { return nil, ErrConnectionClosed } if err := s.processNextMsgDelivered(msg); err != nil { return nil, err } else { return msg, nil } default: } select { case msg, ok ...
c24547
nil { return err } m, err := c.Conn.RequestWithContext(ctx, subject, b) if err != nil { return err } if reflect.TypeOf(vPtr) == emptyMsgType { mPtr := vPtr.(*Msg) *mPtr = *m } else { err := c.Enc.Decode(m.Subject, m.Data, vPtr) if err != nil { return err } } return nil }
c24548
return ErrChanArg } go chPublish(c, chVal, subject) return nil }
c24549
- If the connection is not yet closed, try to schedule the callback if c.Conn.isClosed() { go c.Conn.Opts.AsyncErrorCB(c.Conn, nil, e) } else { c.Conn.ach.push(func() { c.Conn.Opts.AsyncErrorCB(c.Conn, nil, e) }) } } return } } }
c24550
return c.bindRecvChan(subject, _EMPTY_, channel) }
c24551
return c.bindRecvChan(subject, queue, channel) }
c24552
send to a closed channel. // and the user does not know when it is safe to close the channel. defer func() { // If we have panicked, recover and close the subscription. if r := recover(); r != nil { m.Sub.Unsubscribe() } }() // Actually do the send to the channel. chVal.Send(oPtr) } return c....
c24553
geo{} if err := json.Unmarshal(body, &g); err != nil { log.Fatalf("Error unmarshalling geo: %v", err) } return g.Region + ", " + g.Country }
c24554
g.Samples { r := []string{bm.RunID, fmt.Sprintf("%s%d", pre, j), fmt.Sprintf("%d", c.MsgCnt), fmt.Sprintf("%d", c.MsgBytes), fmt.Sprintf("%d", c.Rate()), fmt.Sprintf("%f", c.Throughput()), fmt.Sprintf("%f", c.Duration().Seconds())} if err := writer.Write(r); err != nil { log.Fatalf("Error while serializing %...
c24555
* jobCount) s.MsgCnt = nc.OutMsgs + nc.InMsgs s.IOBytes = nc.OutBytes + nc.InBytes return &s }
c24556
{ return float64(s.MsgBytes) / s.Duration().Seconds() }
c24557
int64(float64(s.JobMsgCnt) / s.Duration().Seconds()) }
c24558
return s.End.Sub(s.Start) }
c24559
:= range sg.Samples { if i == 0 { m = s.Rate() } m = min(m, s.Rate()) } return m }
c24560
:= range sg.Samples { if i == 0 { m = s.Rate() } m = max(m, s.Rate()) } return m }
c24561
uint64(s.Rate()) } return int64(sum / uint64(len(sg.Samples))) }
c24562
math.Pow(float64(c.Rate())-avg, 2) } variance := sum / float64(len(sg.Samples)) return math.Sqrt(variance) }
c24563
} sg.IOBytes += e.IOBytes sg.JobMsgCnt += e.JobMsgCnt sg.MsgCnt += e.MsgCnt sg.MsgBytes += e.MsgBytes if e.Start.Before(sg.Start) { sg.Start = e.Start } if e.End.After(sg.End) { sg.End = e.End } }
c24564
buffer.WriteString(fmt.Sprintf("%s %s\n", indent, bm.Pubs.Statistics())) } } if bm.Subs.HasSamples() { buffer.WriteString(fmt.Sprintf("%sSub stats: %s\n", indent, bm.Subs)) if len(bm.Subs.Samples) > 1 { for i, stat := range bm.Subs.Samples { buffer.WriteString(fmt.Sprintf("%s [%d] %v (%d msgs)\n", ind...
c24565
fmt.Sprintf("%.2f B", bytes) } exp := int(math.Log(bytes) / math.Log(float64(base))) index := exp - 1 units := pre[index] + post return fmt.Sprintf("%.2f %s", bytes/math.Pow(float64(base), float64(exp)), units) }
c24566
counts[i] = mc } extra := numMsgs % numClients for i := 0; i < extra; i++ { counts[i]++ } return counts }
c24567
:= tp.p.Get().(*time.Timer); t != nil { t.Reset(d) return t } return time.NewTimer(d) }
c24568
Severity: gosec.Medium, Confidence: gosec.High, }, Blacklisted: blacklist, }, []ast.Node{(*ast.ImportSpec)(nil)} }
c24569
"crypto/rc4": "Blacklisted import crypto/rc4: weak cryptographic primitive", }) }
c24570
{ if parsedInt, err := strconv.Atoi(configTruncate); err == nil { truncateString = parsedInt } } } return &credentials{ pattern: regexp.MustCompile(pattern), entropyThreshold: entropyThreshold, perCharThreshold: perCharThreshold, ignoreEntropy: ignoreEntropy, truncate: trun...
c24571
id, Severity: gosec.Medium, Confidence: gosec.High, What: "Binds to all network interfaces", }, }, []ast.Node{(*ast.CallExpr)(nil)} }
c24572
calls: []string{"OpenFile", "Chmod"}, MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medium, Confidence: gosec.High, What: fmt.Sprintf("Expect file permissions to be %#o or less", mode), }, }, []ast.Node{(*ast.CallExpr)(nil)} }
c24573
Confidence: gosec.High, What: fmt.Sprintf("RSA keys should be at least %d bits", bits), }, }, []ast.Node{(*ast.CallExpr)(nil)} }
c24574
rule.Add("os/exec", "CommandContext") rule.Add("syscall", "Exec") return rule, []ast.Node{(*ast.CallExpr)(nil)} }
c24575
ok { if selector, ok := assign.Rhs[0].(*ast.SelectorExpr); ok { argType = c.Info.TypeOf(selector.X) } } } } if argType != nil && argType.String() == a.argType { return gosec.NewIssue(c, n, a.ID(), a.What, a.Severity, a.Confidence), nil } } } return nil, nil }
c24576
calls, argType: "*archive/zip.File", MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medium, Confidence: gosec.High, What: "File traversal when extracting zip archive", }, }, []ast.Node{(*ast.CallExpr)(nil)} }
c24577
{ for _, ident := range idents { c.Add(selector, ident) } }
c24578
make(set) } c[selector][ident] = true }
c24579
if typeOf.String() == required { return complit } } return nil }
c24580
== token.INT { return strconv.ParseInt(node.Value, 0, 64) } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
c24581
== token.FLOAT { return strconv.ParseFloat(node.Value, 64) } return 0.0, fmt.Errorf("Unexpected AST node type: %T", n) }
c24582
nil } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
c24583
node.Kind == token.STRING { return strconv.Unquote(node.Value) } return "", fmt.Errorf("Unexpected AST node type: %T", n) }
c24584
switch fn := node.Fun.(type) { case *ast.Ident: return node, ctx.Info.Uses[fn] case *ast.SelectorExpr: return node, ctx.Info.Uses[fn.Sel] } } return nil, nil }
c24585
} return "undefined", fn.Sel.Name, fmt.Errorf("missing type info") } return expr.Name, fn.Sel.Name, nil } case *ast.Ident: return ctx.Pkg.Name(), fn.Name, nil } } return "", "", fmt.Errorf("unable to determine call info") }
c24586
:= arg.(type) { case *ast.BasicLit: value, err := GetString(param) if err == nil { values = append(values, value) } case *ast.Ident: values = append(values, GetIdentStringValues(param)...) } } } return values }
c24587
case *ast.AssignStmt: for _, v := range decl.Rhs { value, err := GetString(v) if err == nil { values = append(values, value) } } } } return values }
c24588
false } if alias, ok := ctx.Imports.Aliased[path]; ok { importName = alias } return importName, true }
c24589
ok && imported == name { return path, true } } return "", false }
c24590
ctx.FileSet.File(n.Pos()) return fobj.Name(), fobj.Line(n.Pos()) }
c24591
strings.Split(path, string(os.PathListSeparator)) for idx, path := range paths { if abs, err := filepath.Abs(path); err == nil { paths[idx] = abs } } return paths }
c24592
val := os.Getenv(key); val != "" { return val } return userDefault }
c24593
if strings.HasPrefix(abspath, projectRoot) { return strings.TrimPrefix(abspath, projectRoot), nil } } return "", errors.New("no project relative path found") }
c24594
return "", errors.New("no project absolute path found") } return absPath, nil }
c24595
:= ConcatString(leftOperand); ok { s = recursion + s } } else if leftOperand, ok := n.X.(*ast.BasicLit); ok { if str, err := GetString(leftOperand); err == nil { s = str + s } } else { return "", false } return s, true }
c24596
else { if leftOperand, ok := n.X.(*ast.Ident); ok { obj := c.Info.ObjectOf(leftOperand) if _, ok := obj.(*types.Var); ok && !TryResolve(leftOperand, c) { identities = append(identities, leftOperand) } } } if len(identities) > 0 { return identities, true } // if nil or error, return false retur...
c24597
} paths[path] = true } return nil }) if err != nil { return []string{}, err } result := []string{} for path := range paths { result = append(result, path) } return result, nil }
c24598
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", }, }, []ast.Node{(*ast.CompositeLit)(nil)} }
c24599
= append(rules, rule) } else { r[t] = []Rule{rule} } } }