Ejemplo n.º 1
0
// makeCapTable converts the clients in the segment's message into capability descriptors.
func (c *Conn) makeCapTable(s *capnp.Segment) (rpccapnp.CapDescriptor_List, error) {
	msgtab := s.Message().CapTable
	t, err := rpccapnp.NewCapDescriptor_List(s, int32(len(msgtab)))
	if err != nil {
		return rpccapnp.CapDescriptor_List{}, nil
	}
	for i, client := range msgtab {
		desc := t.At(i)
		if client == nil {
			desc.SetNone()
			continue
		}
		c.descriptorForClient(desc, client)
	}
	return t, nil
}
Ejemplo n.º 2
0
func bootstrapAndFulfill(t *testing.T, ctx context.Context, conn *rpc.Conn, p rpc.Transport) capnp.Client {
	client, bootstrapID := readBootstrap(t, ctx, conn, p)

	err := sendMessage(ctx, p, func(msg rpccapnp.Message) error {
		ret, err := msg.NewReturn()
		if err != nil {
			return err
		}
		ret.SetAnswerId(bootstrapID)
		payload, err := ret.NewResults()
		if err != nil {
			return err
		}
		payload.SetContent(capnp.NewInterface(msg.Segment(), 0))
		capTable, err := rpccapnp.NewCapDescriptor_List(msg.Segment(), 1)
		if err != nil {
			return err
		}
		capTable.At(0).SetSenderHosted(bootstrapExportID)
		payload.SetCapTable(capTable)
		return nil
	})
	if err != nil {
		t.Fatal("error writing Return:", err)
	}

	if finish, err := p.RecvMessage(ctx); err != nil {
		t.Fatal("error reading Finish:", err)
	} else if finish.Which() != rpccapnp.Message_Which_finish {
		t.Fatalf("message sent is %v; want Message_Which_finish", finish.Which())
	} else {
		f, err := finish.Finish()
		if err != nil {
			t.Fatal(err)
		}
		if id := f.QuestionId(); id != bootstrapID {
			t.Fatalf("finish question ID is %d; want %d", id, bootstrapID)
		}
		if f.ReleaseResultCaps() {
			t.Fatal("finish released bootstrap capability")
		}
	}
	return client
}