Exemple #1
0
func (bsnet *impl) SendMessage(
	ctx context.Context,
	p peer.ID,
	outgoing bsmsg.BitSwapMessage) error {

	s, err := bsnet.newStreamToPeer(ctx, p)
	if err != nil {
		return err
	}
	defer s.Close()

	if err := outgoing.ToNet(s); err != nil {
		log.Debugf("error: %s", err)
		return err
	}

	return err
}
Exemple #2
0
func (bsnet *impl) SendRequest(
	ctx context.Context,
	p peer.ID,
	outgoing bsmsg.BitSwapMessage) (bsmsg.BitSwapMessage, error) {

	s, err := bsnet.newStreamToPeer(ctx, p)
	if err != nil {
		return nil, err
	}
	defer s.Close()

	if err := outgoing.ToNet(s); err != nil {
		log.Debugf("error: %s", err)
		return nil, err
	}

	incoming, err := bsmsg.FromNet(s)
	if err != nil {
		log.Debugf("error: %s", err)
		return incoming, err
	}

	return incoming, nil
}
Exemple #3
0
func (s *streamMessageSender) SendMsg(msg bsmsg.BitSwapMessage) error {
	return msg.ToNet(s.s)
}