func (c *Conn) handleDisembargoMessage(msg rpccapnp.Message) error { d, err := msg.Disembargo() if err != nil { return err } dtarget, err := d.Target() if err != nil { return err } switch d.Context().Which() { case rpccapnp.Disembargo_context_Which_senderLoopback: id := embargoID(d.Context().SenderLoopback()) if dtarget.Which() != rpccapnp.MessageTarget_Which_promisedAnswer { return errDisembargoNonImport } dpa, err := dtarget.PromisedAnswer() if err != nil { return err } aid := answerID(dpa.QuestionId()) a := c.answers.get(aid) if a == nil { return errDisembargoMissingAnswer } dtrans, err := dpa.Transform() if err != nil { return err } transform := promisedAnswerOpsToTransform(dtrans) queued, err := a.queueDisembargo(transform, id, dtarget) if err != nil { return err } if !queued { // There's nothing to embargo; everything's been delivered. resp := newDisembargoMessage(nil, rpccapnp.Disembargo_context_Which_receiverLoopback, id) rd, _ := resp.Disembargo() if err := rd.SetTarget(dtarget); err != nil { return err } c.sendMessage(resp) } case rpccapnp.Disembargo_context_Which_receiverLoopback: id := embargoID(d.Context().ReceiverLoopback()) c.embargoes.disembargo(id) default: um := newUnimplementedMessage(nil, msg) c.sendMessage(um) } return nil }
func formatMsg(w io.Writer, m rpccapnp.Message) { switch m.Which() { case rpccapnp.Message_Which_unimplemented: fmt.Fprint(w, "unimplemented") case rpccapnp.Message_Which_abort: mabort, _ := m.Abort() reason, _ := mabort.Reason() fmt.Fprintf(w, "abort type=%v: %s", mabort.Type(), reason) case rpccapnp.Message_Which_bootstrap: mboot, _ := m.Bootstrap() fmt.Fprintf(w, "bootstrap id=%d", mboot.QuestionId()) case rpccapnp.Message_Which_call: c, _ := m.Call() fmt.Fprintf(w, "call id=%d target=<", c.QuestionId()) tgt, _ := c.Target() formatMessageTarget(w, tgt) fmt.Fprintf(w, "> @%#x/@%d", c.InterfaceId(), c.MethodId()) case rpccapnp.Message_Which_return: r, _ := m.Return() fmt.Fprintf(w, "return id=%d", r.AnswerId()) if r.ReleaseParamCaps() { fmt.Fprint(w, " releaseParamCaps") } switch r.Which() { case rpccapnp.Return_Which_results: case rpccapnp.Return_Which_exception: exc, _ := r.Exception() reason, _ := exc.Reason() fmt.Fprintf(w, ", exception type=%v: %s", exc.Type(), reason) case rpccapnp.Return_Which_canceled: fmt.Fprint(w, ", canceled") case rpccapnp.Return_Which_resultsSentElsewhere: fmt.Fprint(w, ", results sent elsewhere") case rpccapnp.Return_Which_takeFromOtherQuestion: fmt.Fprint(w, ", results sent elsewhere") case rpccapnp.Return_Which_acceptFromThirdParty: fmt.Fprint(w, ", accept from third party") default: fmt.Fprintf(w, ", UNKNOWN RESULT which=%v", r.Which()) } case rpccapnp.Message_Which_finish: fin, _ := m.Finish() fmt.Fprintf(w, "finish id=%d", fin.QuestionId()) if fin.ReleaseResultCaps() { fmt.Fprint(w, " releaseResultCaps") } case rpccapnp.Message_Which_resolve: r, _ := m.Resolve() fmt.Fprintf(w, "resolve id=%d ", r.PromiseId()) switch r.Which() { case rpccapnp.Resolve_Which_cap: fmt.Fprint(w, "capability=") c, _ := r.Cap() formatCapDescriptor(w, c) case rpccapnp.Resolve_Which_exception: exc, _ := r.Exception() reason, _ := exc.Reason() fmt.Fprintf(w, "exception type=%v: %s", exc.Type(), reason) default: fmt.Fprintf(w, "UNKNOWN RESOLUTION which=%v", r.Which()) } case rpccapnp.Message_Which_release: rel, _ := m.Release() fmt.Fprintf(w, "release id=%d by %d", rel.Id(), rel.ReferenceCount()) case rpccapnp.Message_Which_disembargo: de, _ := m.Disembargo() tgt, _ := de.Target() fmt.Fprint(w, "disembargo <") formatMessageTarget(w, tgt) fmt.Fprint(w, "> ") dc := de.Context() switch dc.Which() { case rpccapnp.Disembargo_context_Which_senderLoopback: fmt.Fprintf(w, "sender loopback id=%d", dc.SenderLoopback()) case rpccapnp.Disembargo_context_Which_receiverLoopback: fmt.Fprintf(w, "receiver loopback id=%d", dc.ReceiverLoopback()) case rpccapnp.Disembargo_context_Which_accept: fmt.Fprint(w, "accept") case rpccapnp.Disembargo_context_Which_provide: fmt.Fprintf(w, "provide id=%d", dc.Provide()) default: fmt.Fprintf(w, "UNKNOWN CONTEXT which=%v", dc.Which()) } case rpccapnp.Message_Which_obsoleteSave: fmt.Fprint(w, "save") case rpccapnp.Message_Which_obsoleteDelete: fmt.Fprint(w, "delete") case rpccapnp.Message_Which_provide: prov, _ := m.Provide() tgt, _ := prov.Target() fmt.Fprintf(w, "provide id=%d <", prov.QuestionId()) formatMessageTarget(w, tgt) fmt.Fprint(w, ">") case rpccapnp.Message_Which_accept: acc, _ := m.Accept() fmt.Fprintf(w, "accept id=%d", acc.QuestionId()) if acc.Embargo() { fmt.Fprint(w, " with embargo") } case rpccapnp.Message_Which_join: join, _ := m.Join() tgt, _ := join.Target() fmt.Fprintf(w, "join id=%d <", join.QuestionId()) formatMessageTarget(w, tgt) fmt.Fprint(w, ">") default: fmt.Fprintf(w, "UNKNOWN MESSAGE which=%v", m.Which()) } }