~fnux/yggdrasil-go-coap

4d60089651dfdc4b0f0ff5011c121c53535dfd5b — Jozef Kralik 1 year, 10 months ago 6cb733c
Disable peer tcp signal message CSMs (#54)

iotivity, iotivity-lite send CSM with max message size without
blockwise flag and it limits size of whole message. The feature
avoid the limitation.


3 files changed, 25 insertions(+), 16 deletions(-)

M client.go
M server.go
M sessiontcp.go
M client.go => client.go +13 -11
@@ 41,8 41,9 @@ type Client struct {
	BlockWiseTransfer    *bool         // Use blockWise transfer for transfer payload (default for UDP it's enabled, for TCP it's disable)
	BlockWiseTransferSzx *BlockWiseSzx // Set maximal block size of payload that will be send in fragment

	DisableTCPSignalMessages bool // Disable tcp signal messages
	MulticastHopLimit        int  //sets the hop limit field value for future outgoing multicast packets. default is 2.
	DisableTCPSignalMessages        bool // Disable tcp signal messages
	DisablePeerTCPSignalMessageCSMs bool // Disable processes Capabilities and Settings Messages from client - iotivity sends max message size without blockwise.
	MulticastHopLimit               int  //sets the hop limit field value for future outgoing multicast packets. default is 2.
}

func (c *Client) readTimeout() time.Duration {


@@ 170,15 171,16 @@ func (c *Client) DialWithContext(ctx context.Context, address string) (clientCon
	//sync := make(chan bool)
	clientConn = &ClientConn{
		srv: &Server{
			Net:                      network,
			TLSConfig:                c.TLSConfig,
			Conn:                     conn,
			ReadTimeout:              c.readTimeout(),
			WriteTimeout:             c.writeTimeout(),
			MaxMessageSize:           c.MaxMessageSize,
			BlockWiseTransfer:        &BlockWiseTransfer,
			BlockWiseTransferSzx:     &BlockWiseTransferSzx,
			DisableTCPSignalMessages: c.DisableTCPSignalMessages,
			Net:                              network,
			TLSConfig:                        c.TLSConfig,
			Conn:                             conn,
			ReadTimeout:                      c.readTimeout(),
			WriteTimeout:                     c.writeTimeout(),
			MaxMessageSize:                   c.MaxMessageSize,
			BlockWiseTransfer:                &BlockWiseTransfer,
			BlockWiseTransferSzx:             &BlockWiseTransferSzx,
			DisableTCPSignalMessages:         c.DisableTCPSignalMessages,
			DisablePeerTCPSignalMessageCSMs: c.DisablePeerTCPSignalMessageCSMs,
			NotifyStartedFunc: func() {
				close(started)
			},

M server.go => server.go +3 -1
@@ 164,8 164,10 @@ type Server struct {
	BlockWiseTransfer *bool
	// Set maximal block size of payload that will be send in fragment
	BlockWiseTransferSzx *BlockWiseSzx
	// Disable tcp signal messages
	// Disable send tcp signal messages
	DisableTCPSignalMessages bool
	// Disable processes Capabilities and Settings Messages from client - iotivity sends max message size without blockwise.
	DisablePeerTCPSignalMessageCSMs bool

	// UDP packet or TCP connection queue
	queue chan *Request

M sessiontcp.go => sessiontcp.go +9 -4
@@ 14,8 14,9 @@ type sessionTCP struct {
	sessionBase
	connection *coapNet.Conn

	peerBlockWiseTransfer uint32
	peerMaxMessageSize    uint32
	peerBlockWiseTransfer           uint32
	peerMaxMessageSize              uint32
	disablePeerTCPSignalMessageCSMs bool
}

// newSessionTCP create new session for TCP connection


@@ 29,8 30,9 @@ func newSessionTCP(connection *coapNet.Conn, srv *Server) (networkSession, error
		BlockWiseTransferSzx = *srv.BlockWiseTransferSzx
	}
	s := &sessionTCP{
		peerMaxMessageSize: uint32(srv.MaxMessageSize),
		connection:         connection,
		peerMaxMessageSize:              uint32(srv.MaxMessageSize),
		disablePeerTCPSignalMessageCSMs: srv.DisablePeerTCPSignalMessageCSMs,
		connection:                      connection,
		sessionBase: sessionBase{
			srv:                  srv,
			handler:              &TokenHandler{tokenHandlers: make(map[[MaxTokenSize]byte]HandlerFunc)},


@@ 208,6 210,9 @@ func (s *sessionTCP) sendPong(w ResponseWriter, r *Request) error {
func (s *sessionTCP) handleSignals(w ResponseWriter, r *Request) bool {
	switch r.Msg.Code() {
	case CSM:
		if s.disablePeerTCPSignalMessageCSMs {
			return true
		}
		maxmsgsize := uint32(maxMessageSize)
		if size, ok := r.Msg.Option(MaxMessageSize).(uint32); ok {
			s.setPeerMaxMessageSize(size)