func (handle RequestPayloadHandler) MakeStreamHandler(newCtx StreamCtxFn, comp Compression, minRequestContentSize, maxRequestContentSize uint64) network.StreamHandler {
	return func(stream network.Stream) {
		peerId := stream.Conn().RemotePeer()
		ctx, cancel := context.WithCancel(newCtx())
		defer cancel()
		go func() {
			<-ctx.Done()
			_ = stream.Close()  
		}()
		w := io.WriteCloser(stream)
		if maxRequestContentSize == 0 {
			handle(ctx, peerId, 0, nil, w, comp, nil)
			return
		}
		var invalidInputErr error
		blr := NewBufLimitReader(stream, requestBufferSize, 0)
		blr.N = 1  
		blr.PerRead = true
		reqLen, err := binary.ReadUvarint(blr)
		blr.PerRead = false
		if err != nil {
			invalidInputErr = err
		} else if reqLen < minRequestContentSize {
			invalidInputErr = fmt.Errorf("request length %d is unexpectedly small, request size minimum is %d", reqLen, minRequestContentSize)
		} else if reqLen > maxRequestContentSize {
			invalidInputErr = fmt.Errorf("request length %d exceeds request size limit %d", reqLen, maxRequestContentSize)
		} else if comp != nil {
			s, err := comp.MaxEncodedLen(maxRequestContentSize)
			if err != nil {
				invalidInputErr = err
			} else {
				maxRequestContentSize = s
			}
		}
		if invalidInputErr != nil {
			maxRequestContentSize = 0
		}
		if comp == nil {
			blr.N = int(maxRequestContentSize)
		} else {
			v, err := comp.MaxEncodedLen(maxRequestContentSize)
			if err != nil {
				blr.N = int(maxRequestContentSize)
			} else {
				blr.N = int(v)
			}
		}
		r := io.Reader(blr)
		handle(ctx, peerId, reqLen, r, w, comp, invalidInputErr)
	}
}
startReqRPC registers a request handler for the given protocol. Compression is optional and may be nil.
package reqresp
import (
	"context"
	"encoding/binary"
	"fmt"
	"github.com/libp2p/go-libp2p-core/network"
	"github.com/libp2p/go-libp2p-core/peer"
	"io"
)
const requestBufferSize = 2048
type RequestPayloadHandler func(ctx context.Context, peerId peer.ID, requestLen uint64, r io.Reader, w io.Writer, comp Compression, invalidInputErr error)
type StreamCtxFn func() context.Context