~fnux/yggdrasil-go-coap

eef8a26222ab1ac9fea229345671e22647f5b328 — Jozef Kralik 2 years ago e042d7b
set unlimited MaxMessageSize as default
2 files changed, 5 insertions(+), 6 deletions(-)

M networksession.go
M server.go
M networksession.go => networksession.go +3 -1
@@ 516,7 516,9 @@ func (s *sessionTCP) sendCSM() error {
		Code:  CSM,
		Token: []byte(token),
	})
	req.AddOption(MaxMessageSize, uint32(s.srv.MaxMessageSize))
	if s.srv.MaxMessageSize != 0 {
		req.AddOption(MaxMessageSize, uint32(s.srv.MaxMessageSize))
	}
	if s.blockWiseEnabled() {
		req.AddOption(BlockWiseTransfer, []byte{})
	}

M server.go => server.go +2 -5
@@ 131,7 131,7 @@ type Server struct {
	// Handler to invoke, COAP.DefaultServeMux if nil.
	Handler Handler
	// Max message size that could be received from peer. Min 16bytes. If not set
	// it defaults to 1152 B.
	// it defaults is unlimited.
	MaxMessageSize uint32
	// The net.Conn.SetReadTimeout value for new connections, defaults to 1hour.
	ReadTimeout time.Duration


@@ 320,10 320,7 @@ func (srv *Server) ActivateAndServe() error {
	pConn := srv.Conn
	l := srv.Listener

	if srv.MaxMessageSize == 0 {
		srv.MaxMessageSize = maxMessageSize
	}
	if srv.MaxMessageSize < uint32(szxToBytes[BlockWiseSzx16]) {
	if srv.MaxMessageSize > 0 && srv.MaxMessageSize < uint32(szxToBytes[BlockWiseSzx16]) {
		return ErrInvalidMaxMesssageSizeParameter
	}