id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c178100
httpRes.Close() if httpRes.Error != nil { return httpRes.Error } return lateErr } return httpRes.Decode(res) }
c178101
from, err := peer.IDFromBytes(r.From) if err != nil { return nil, err } return &Message{ From: from, Data: r.Data, Seqno: r.Seqno, TopicIDs: r.TopicIDs, }, nil }
c178102
s.resp.Output == nil { return nil } return s.resp.Output.Close() }
c178103
range out.Objects { return object, nil } return nil, fmt.Errorf("no object in results") }
c178104
if err != nil { return nil, err } if resp.Error != nil { return nil, resp.Error } return resp.Output, nil }
c178105
1 { return nil, errors.New("bad response from server") } return out.Objects[0].Links, nil }
c178106
true). Exec(context.Background(), nil) }
c178107
return raw.Keys, s.Request("pin/ls").Exec(context.Background(), &raw) }
c178108
err != nil { return "", "", err } return ver.Version, ver.Commit, nil }
c178109
s.Request("swarm/peers").Exec(ctx, &v) return v, err }
c178110
:= s.Request("swarm/connect"). Arguments(addr...). Exec(ctx, &conn) return err }
c178111
"cbor", Pin: "false", Hash: "sha2-256", } for _, opt := range opts { err := opt(options) if err != nil { return nil, err } } return options, nil }
c178112
func(opts *DagPutSettings) error { opts.Pin = pin return nil } }
c178113
func(opts *DagPutSettings) error { opts.Kind = kind return nil } }
c178114
func(opts *DagPutSettings) error { opts.Hash = hash return nil } }
c178115
resp.Error != nil { return "", resp.Error } dec := json.NewDecoder(resp.Output) var final string for { var out object err = dec.Decode(&out) if err != nil { if err == io.EOF { break } return "", err } final = out.Hash } if final == "" { return "", errors.New("no results received") } return final, nil }
c178116
req.Arguments(node) } req.Arguments(value) return req.Exec(context.Background(), &pubResp) }
c178117
{ req.Option("lifetime", lifetime) } if ttl.Seconds() > 0 { req.Option("ttl", ttl) } err := req.Exec(context.Background(), &pubResp) if err != nil { return nil, err } return &pubResp, nil }
c178118
case !pv.Value.IsNull(): return pv.Value, nil case pv.ListKey != "" || pv.Values != nil: // This code is unreachable because the parser does not allow // multi-value constructs where a single value is expected. return NULL, errors.New("a list was supplied where a single value was expected") } return NULL, nil }
c178119
buf.WriteString(pq.Query[current:loc.offset]) name := pq.Query[loc.offset : loc.offset+loc.length] if encodable, ok := extras[name[1:]]; ok { encodable.EncodeSQL(buf) } else { supplied, _, err := FetchBindVar(name, bindVariables) if err != nil { return nil, err } EncodeValue(buf, supplied) } current = loc.offset + loc.length } buf.WriteString(pq.Query[current:]) return buf.Bytes(), nil }
c178120
buf.WriteByte('(') for i, bv := range value.Values { if i != 0 { buf.WriteString(", ") } sqltypes.ProtoToValue(bv).EncodeSQL(buf) } buf.WriteByte(')') }
c178121
= tkn.Scan() } lval.bytes = val tkn.lastToken = val return typ }
c178122
{ tkn.next() ch = tkn.lastChar } }
c178123
= nil tkn.specialComment = nil tkn.posVarIndex = 0 tkn.nesting = 0 tkn.ForceEOF = false }
c178124
return StmtBegin case "commit": return StmtCommit case "rollback": return StmtRollback } switch loweredFirstWord { case "create", "alter", "rename", "drop", "truncate": return StmtDDL case "set": return StmtSet case "show": return StmtShow case "use": return StmtUse case "analyze", "describe", "desc", "explain", "repair", "optimize": return StmtOther } if strings.Index(trimmed, "/*!") == 0 { return StmtComment } return StmtUnknown }
c178125
NewPlanValue(val) if err != nil { return sqltypes.PlanValue{}, err } if innerpv.ListKey != "" || innerpv.Values != nil { return sqltypes.PlanValue{}, errors.New("unsupported: nested lists") } pv.Values = append(pv.Values, innerpv) } return pv, nil case *NullVal: return sqltypes.PlanValue{}, nil } return sqltypes.PlanValue{}, fmt.Errorf("expression is too complex '%v'", String(node)) }
c178126
str == val { return true } } return false }
c178127
new(bytes.Buffer), nodeFormatter: nodeFormatter, } }
c178128
pstring := (*reflect.StringHeader)(unsafe.Pointer(&sa.str)) pstring.Data = pbytes.Data pstring.Len = pbytes.Cap return sa }
c178129
start := len(sa.buf) sa.buf = append(sa.buf, b...) return sa.str[start : start+len(b)] }
c178130
cap(sa.buf) - len(sa.buf) }
c178131
nil, tokenizer.LastError } return tokenizer.ParseTree, nil }
c178132
if tokenizer.partialDDL != nil { tokenizer.ParseTree = tokenizer.partialDDL return tokenizer.ParseTree, nil } return nil, tokenizer.LastError } return tokenizer.ParseTree, nil }
c178133
{ tbuf := &TrackedBuffer{ Buffer: buf, } node.Format(tbuf) }
c178134
return NewStrVal(value.ToBytes()), nil default: // We cannot support sqltypes.Expression, or any other invalid type. return nil, fmt.Errorf("cannot convert value %v to AST", value) } }
c178135
buf.WriteByte('`') } } buf.WriteByte('`') return buf.String() }
c178136
err != nil { return NULL, err } return MakeTrusted(typ, val), nil case IsQuoted(typ) || typ == Null: return MakeTrusted(typ, val), nil } // All other types are unsafe or invalid. return NULL, fmt.Errorf("invalid type specified for MakeValue: %v", typ) }
c178137
v.IsQuoted() { return fmt.Sprintf("%v(%q)", v.typ, v.val) } return fmt.Sprintf("%v(%s)", v.typ, v.val) }
c178138
b.Write(nullstr) case v.IsQuoted(): encodeBytesSQL(v.val, b) default: b.Write(v.val) } }
c178139
if j != 0 { buf.WriteString(", ") } bv.EncodeSQL(buf) } buf.WriteByte(')') } }
c178140
if len(tpl.Columns) == 1 { tpl.encodeAsIn(buf) return } tpl.encodeAsEquality(buf) }
c178141
// Don't continue return false, nil case *SQLVal: nz.convertSQLVal(node) case *ComparisonExpr: nz.convertComparison(node) } return true, nil }
c178142
*ComparisonExpr: nz.convertComparison(node) } return true, nil }
c178143
return reflect.DeepEqual(&querypb.BoundQuery{BindVariables: x}, &querypb.BoundQuery{BindVariables: y}) }
c178144
opts.ErrorHandler = OnError } if opts.Extractor == nil { opts.Extractor = FromAuthHeader } return &JWTMiddleware{ Options: opts, } }
c178145
If there was an error, do not call next. if err == nil && next != nil { next(w, r) } }
c178146
bit more robust, parsing-wise authHeaderParts := strings.Split(authHeader, " ") if len(authHeaderParts) != 2 || strings.ToLower(authHeaderParts[0]) != "bearer" { return "", errors.New("Authorization header format must be Bearer {token}") } return authHeaderParts[1], nil }
c178147
{ return r.URL.Query().Get(param), nil } }
c178148
!= nil { return "", err } if token != "" { return token, nil } } return "", nil } }
c178149
Subscribe: proto.Bool(true), } rpc.Subscriptions = append(rpc.Subscriptions, as) } return &rpc }
c178150
protocols: ps, } return NewPubSub(ctx, h, rt, opts...) }
c178151
return NewFloodsubWithProtocols(ctx, h, []protocol.ID{FloodSubID}, opts...) }
c178152
nil, err } b := &LRUBlacklist{lru: c} return b, nil }
c178153
{ rt := &RandomSubRouter{ peers: make(map[peer.ID]protocol.ID), } return NewPubSub(ctx, h, rt, opts...) }
c178154
fanout: make(map[string]map[peer.ID]struct{}), lastpub: make(map[string]int64), gossip: make(map[peer.ID][]*pb.ControlIHave), control: make(map[peer.ID]*pb.ControlMessage), mcache: NewMessageCache(GossipSubHistoryGossip, GossipSubHistoryLength), } return NewPubSub(ctx, h, rt, opts...) }
c178155
make(chan *sendReq, 32), addVal: make(chan *addValReq), rmVal: make(chan *rmValReq), validateThrottle: make(chan struct{}, defaultValidateThrottle), eval: make(chan func()), myTopics: make(map[string]map[*Subscription]struct{}), topics: make(map[string]map[peer.ID]struct{}), peers: make(map[peer.ID]chan *RPC), topicVals: make(map[string]*topicVal), blacklist: NewMapBlacklist(), blacklistPeer: make(chan peer.ID), seenMessages: timecache.NewTimeCache(TimeCacheDuration), counter: uint64(time.Now().UnixNano()), } for _, opt := range opts { err := opt(ps) if err != nil { return nil, err } } if ps.signStrict && ps.signKey == nil { return nil, fmt.Errorf("strict signature verification enabled but message signing is disabled") } rt.Attach(ps) for _, id := range rt.Protocols() { h.SetStreamHandler(id, ps.handleNewStream) } h.Network().Notify((*PubSubNotif)(ps)) go ps.processLoop(ctx) return ps, nil }
c178156
ps.validateThrottle = make(chan struct{}, n) return nil } }
c178157
p.blacklist = b return nil } }
c178158
if len(subs) == 0 { delete(p.myTopics, sub.topic) p.announce(sub.topic, false) p.rt.Leave(sub.topic) } }
c178159
p.myTopics[sub.topic] = make(map[*Subscription]struct{}) subs = p.myTopics[sub.topic] } sub.ch = make(chan *Message, 32) sub.cancelCh = p.cancelCh p.myTopics[sub.topic][sub] = struct{}{} req.resp <- sub }
c178160
default: log.Infof("Can't send announce message to peer %s: queue full; scheduling retry", pid) go p.announceRetry(pid, topic, sub) } } }
c178161
default: log.Infof("Can't deliver message to subscription for topic %s; subscriber too slow", topic) } } } }
c178162
return p.seenMessages.Has(id) }
c178163
false } for _, t := range msg.GetTopicIDs() { if _, ok := p.myTopics[t]; ok { return true } } return false }
c178164
return string(pmsg.GetFrom()) + string(pmsg.GetSeqno()) }
c178165
// network traffic; each validator also has an individual throttle to preclude // slow (or faulty) validators from starving other topics; see validate below. select { case p.validateThrottle <- struct{}{}: go func() { p.validate(vals, src, msg) <-p.validateThrottle }() default: log.Warningf("message validation throttled; dropping message from %s", src) } return } p.publishMessage(src, msg.Message) }
c178166
src) return } } if len(vals) > 0 { if !p.validateTopic(vals, src, msg) { log.Warningf("message validation failed; dropping message from %s", src) return } } // all validators were successful, send the message p.sendMsg <- &sendReq{ from: src, msg: msg, } }
c178167
context.WithCancel(p.ctx) defer cancel() res := val.validateMsg(ctx, src, msg) <-val.validateThrottle return res default: log.Debugf("validation throttled for topic %s", val.topic) return false } }
c178168
p.topicVals[topic] if !ok { continue } vals = append(vals, val) } return vals }
c178169
error) { td := pb.TopicDescriptor{Name: &topic} return p.SubscribeByTopicDescriptor(&td, opts...) }
c178170
{ return nil, fmt.Errorf("encryption mode not yet supported") } sub := &Subscription{ topic: td.GetName(), } for _, opt := range opts { err := opt(sub) if err != nil { return nil, err } } out := make(chan *Subscription, 1) p.addSub <- &addSubReq{ sub: sub, resp: out, } return <-out, nil }
c178171
<- &topicReq{resp: out} return <-out }
c178172
!= nil { m.From = []byte(p.signID) err := signMessage(p.signID, p.signKey, m) if err != nil { return err } } p.publish <- &Message{m} return nil }
c178173
&listPeerReq{ resp: out, topic: topic, } return <-out }
c178174
{ return func(addVal *addValReq) error { addVal.timeout = timeout return nil } }
c178175
{ addVal.throttle = n return nil } }
c178176
topic, validate: val, resp: make(chan error, 1), } for _, opt := range opts { err := opt(addVal) if err != nil { return err } } p.addVal <- addVal return <-addVal.resp }
c178177
make(chan error, 1), } p.rmVal <- rmVal return <-rmVal.resp }
c178178
MetricWithPrefix("tchannel.", name, tags) }
c178179
case strings.HasPrefix(name, "inbound"): addKeys = append(addKeys, "calling-service", "service", "endpoint") } for _, k := range addKeys { buf.WriteByte('.') v, ok := tags[k] if ok { writeClean(buf, v) } else { buf.WriteString("no-") buf.WriteString(k) } } m := buf.String() bufPool.Put(buf) return m }
c178180
targetService, } if opts != nil && opts.HostPort != "" { client.hostPort = opts.HostPort } return client }
c178181
}) if err != nil { return err } isOK, errAt, err = makeCall(call, headers, arg, &respHeaders, resp, &respErr) return err }) if err != nil { // TODO: Don't lose the error type here. return fmt.Errorf("%s: %v", errAt, err) } if !isOK { return respErr } return nil }
c178182
&tchannel.CallOptions{Format: tchannel.JSON}) if err != nil { return err } return wrapCall(ctx, call, method, arg, resp) }
c178183
tchannel.JSON}) if err != nil { return err } return wrapCall(ctx, call, method, arg, resp) }
c178184
Header: make(http.Header), } readHeaders(rb, response.Header) if err := rb.Err(); err != nil { return nil, err } arg3Reader, err := call.Arg3Reader() if err != nil { return nil, err } response.Body = arg3Reader return response, nil }
c178185
w.err = err return } if _, w.err = wb.FlushTo(arg2Writer); w.err != nil { return } if w.err = arg2Writer.Close(); w.err != nil { return } w.arg3Writer, w.err = w.response.Arg3Writer() }
c178186
:= newTChanResponseWriter(response) return responseWriter, responseWriter.finish }
c178187
err := readHeaders(reader) reader.Release() return m, err }
c178188
dst net.Conn) { io.Copy(src, dst) }) }
c178189
nil, err } // Add the given initial nodes as peers. for _, node := range config.InitialNodes { addPeer(ch, node) } client.jsonClient = tjson.NewClient(ch, hyperbahnServiceName, nil) thriftClient := tthrift.NewClient(ch, hyperbahnServiceName, nil) client.hyperbahnClient = htypes.NewTChanHyperbahnClient(thriftClient) return client, nil }
c178190
{ return err } c.opts.Handler.On(Advertised) go c.advertiseLoop() return nil }
c178191
return call.Response().SendSystemError(serr) } call.Response().SetApplicationError() // TODO(prashant): Allow client to customize the error in more ways. res = struct { Type string `json:"type"` Message string `json:"message"` }{ Type: "error", Message: err.(error).Error(), } } if err := tchannel.NewArgWriter(call.Response().Arg2Writer()).WriteJSON(ctx.ResponseHeaders()); err != nil { return err } return tchannel.NewArgWriter(call.Response().Arg3Writer()).WriteJSON(res) }
c178192
ch.ListenAndServe(s.HostPort); err != nil { return err } s.HostPort = ch.PeerInfo().HostPort // override in case it was ":0" log.Printf("Started tchannel server at %s\n", s.HostPort) s.Ch = ch return nil }
c178193
hostPortSplit[len(hostPortSplit)-1] return port }
c178194
{ newScore := l.scoreCalculator.GetScore(ps.Peer) l.updatePeer(ps, newScore) } }
c178195
:= newPeerScore(p, l.scoreCalculator.GetScore(p)) l.peersByHostPort[hostPort] = ps l.peerHeap.addPeer(ps) return p }
c178196
peer := l.choosePeer(prevSelected, true /* avoidHost */) if peer == nil { peer = l.choosePeer(prevSelected, false /* avoidHost */) } if peer == nil { return nil, ErrNoNewPeers } return peer, nil }
c178197
else if err != nil { return nil, err } if peer == nil { return nil, ErrNoPeers } return peer, nil }
c178198
} p.delSC() delete(l.peersByHostPort, hostPort) l.peerHeap.removePeer(p) return nil }
c178199
:= make(map[string]*Peer) for k, v := range l.peersByHostPort { listCopy[k] = v.Peer } return listCopy }