Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #122

Merged
merged 82 commits into from
May 27, 2020
Merged

V2 #122

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
5701576
tcp version 1.0
jkralik Nov 9, 2018
15791f7
transform code to pure tcp server
jkralik Nov 26, 2018
83d1004
create RequestMsg
jkralik Dec 1, 2018
d6d18f2
extends request msg
jkralik Dec 4, 2018
28fbcb0
set NonConfirmable as default for client requests
jkralik Apr 20, 2020
3984b62
add test for confirmable message
jkralik Apr 20, 2020
7893a8b
rewrite using messageID
jkralik Apr 20, 2020
c0235b9
Merge branch 'v2' into changeDefaultToNonConfirmable
jkralik Apr 20, 2020
836361e
separate TCP protocol
jkralik Apr 21, 2020
aa61fa4
replace errorCode by error, runable test
jkralik Apr 22, 2020
a15ce6f
impl udp message parser
jkralik Apr 22, 2020
01c5f41
blockwise rewriting
jkralik Apr 24, 2020
ad16a55
blockwise with tests
jkralik Apr 27, 2020
d141f8d
integrate blockwise to udp + implement observe to client
jkralik Apr 28, 2020
fcbc8f6
udp: implement write request
jkralik Apr 28, 2020
5e92370
add PUT, POST, DELETE ops to clientconn
jkralik Apr 28, 2020
6bdd848
fix observation of resources by RFC
jkralik Apr 30, 2020
1c3c917
register get request for observation to get resource content
jkralik Apr 30, 2020
139a7b4
update comments
jkralik May 3, 2020
3ae97b5
examples of usage
jkralik May 3, 2020
06fe12f
implement noreponse
jkralik May 3, 2020
de985b4
Merge branch 'separateProtocols' of github.com:go-ocf/go-coap into se…
jkralik May 3, 2020
b306678
Update options.go
jkralik May 3, 2020
f8a63f6
update comments
jkralik May 3, 2020
80bb6e9
Update options.go
jkralik May 3, 2020
54412ff
update tcp about coap features from udp
jkralik May 4, 2020
d026f11
dlts client+server, add options to all protocols
jkralik May 5, 2020
c5c3ced
provides Context for mux.ClientConn
jkralik May 6, 2020
0ac6d78
update observe example
jkralik May 6, 2020
649e867
fix tests
jkralik May 6, 2020
6f9892a
Merge branch 'master' into v2
jkralik May 6, 2020
7e44012
update README.md
jkralik May 6, 2020
9f6da87
update README.md to newest packages
jkralik May 6, 2020
ea2dfd2
remove debug logs
jkralik May 6, 2020
d1c6824
proper handle udp/dtls confirmable requests + retry
jkralik May 6, 2020
bf660f8
fix tests for windows
jkralik May 7, 2020
080f9c1
merge clients of udp and dtls
jkralik May 7, 2020
7210806
add support for retransmission for writeRequest
jkralik May 7, 2020
474ab7b
renames XYZPayloadXYZ to BodySize and SetBody
jkralik May 7, 2020
3dc2b01
add Client function
jkralik May 7, 2020
1306359
Update README.md
jkralik May 7, 2020
1afd3a6
propagate sequence number over blockwise
jkralik May 8, 2020
959d26f
Merge branch 'v2' of github.com:go-ocf/go-coap into v2
jkralik May 8, 2020
2254d5e
add badget's about backer's and sponsor's
jkralik May 8, 2020
288a064
add description about golang
jkralik May 8, 2020
a5c04b3
add transmission option
jkralik May 8, 2020
bedc77d
link to examples
jkralik May 8, 2020
4c4119f
add new lines
jkralik May 8, 2020
22708b7
Update README.md
jkralik May 10, 2020
a31f765
Update README.md
jkralik May 10, 2020
84c3375
fix DTLS accept loop from exiting
jkralik May 11, 2020
a57b98d
extends Options about Path(), Queries(), ContentFormat()
jkralik May 11, 2020
1280df8
move muxclient as client with common interface for tcp/udp
jkralik May 11, 2020
eddd3e0
add docs for blockwise
jkralik May 12, 2020
a083f59
send reset when observation was not found
jkralik May 12, 2020
0d55403
move conversion function's to pool package
jkralik May 12, 2020
721de6f
fix casting nil value to interface
jkralik May 12, 2020
8cce191
set type Confirmable and MessageID for every client.do
jkralik May 12, 2020
cbe4f1b
fix blockwise for Block1
jkralik May 13, 2020
95d4a93
rename WriteRequest to WriteMessage
jkralik May 13, 2020
9a5754c
fix set option id + stop do function when all was send
jkralik May 13, 2020
1911368
send confirmation message always via udp/writeRequest
jkralik May 13, 2020
97c259b
rename writeRequest to writeMessage
jkralik May 13, 2020
8233f9d
rename mux.ResponseWriter.ClientConn to mux.ResponseWriter.Client
jkralik May 14, 2020
09bfcd2
propagate sequence number to request in mux.Handler
jkralik May 15, 2020
3037f9e
exports Sequence function from client/clientconn
jkralik May 18, 2020
a6e3ed0
add {Set}Observe to message.Options
jkralik May 20, 2020
4843690
add middleware support to router
jkralik May 20, 2020
4396a67
exports NewDeleteRequest for tcp/udp
jkralik May 20, 2020
ccff055
export {Set}Accept for convinience from options
jkralik May 20, 2020
8deb263
fix shutdown of tcp/dtls server
jkralik May 21, 2020
1e541e1
fix WithTLS option for tcp
jkralik May 21, 2020
e13e257
returns valid observe response Code
jkralik May 21, 2020
1fcd6e6
get's underlaying client connection from client
jkralik May 22, 2020
1dc6fb1
test with -race flag
jkralik May 22, 2020
df944db
fix target build
jkralik May 22, 2020
1d4d4f7
clean up after CR
jkralik May 26, 2020
173b031
Merge branch 'master' into v2
jkralik May 26, 2020
7c6854c
clean up 2 for CR
jkralik May 26, 2020
da9edec
clean up 3 for CR
jkralik May 27, 2020
103a8a0
cleanup 3 after CR
jkralik May 27, 2020
84883e5
cleanup server.Serve function
jkralik May 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename WriteRequest to WriteMessage
  • Loading branch information
jkralik committed May 13, 2020
commit 95d4a93283bdb9a1b80b99de8e30e4bd8f6469b5
53 changes: 27 additions & 26 deletions blockwise/blockwise.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Message interface {
ResetOptionsTo(message.Options)
SetBody(r io.ReadSeeker)
SetSequence(uint64)
String() string
}

// EncodeBlockOption encodes block values to coap option.
Expand Down Expand Up @@ -184,7 +185,7 @@ func bufferSize(szx SZX, maxMessageSize int) int {
return (maxMessageSize / szx.Size()) * szx.Size()
}

// Do sends an coap request and returns an coap response via blockwise transfer.
// Do sends an coap message and returns an coap response via blockwise transfer.
func (b *BlockWise) Do(r Message, maxSzx SZX, maxMessageSize int, do func(req Message) (Message, error)) (Message, error) {
if maxSzx > SZXBERT {
return nil, fmt.Errorf("invalid szx")
Expand All @@ -193,36 +194,33 @@ func (b *BlockWise) Do(r Message, maxSzx SZX, maxMessageSize int, do func(req Me
return nil, fmt.Errorf("invalid token")
}

blockID := message.Block2
sizeID := message.Size2
switch r.Code() {
case codes.POST, codes.PUT:
blockID = message.Block1
sizeID = message.Size1
}

req := b.acquireMessage(r.Context())
defer b.releaseMessage(req)
req.SetCode(r.Code())
req.SetToken(r.Token())
req.ResetOptionsTo(r.Options())

tokenStr := r.Token().String()
b.bwSendedRequest.Store(tokenStr, req)
defer b.bwSendedRequest.Delete(tokenStr)

if r.Body() == nil {
resp, err := do(r)
return resp, err
return do(r)
}
payloadSize, err := r.BodySize()
if err != nil {
return nil, fmt.Errorf("cannot get size of payload: %w", err)
}

if payloadSize <= int64(maxSzx.Size()) {
return do(r)
}
req.SetOptionUint32(sizeID, uint32(payloadSize))

switch r.Code() {
case codes.POST, codes.PUT:
break
default:
return nil, fmt.Errorf("no supported command(%v)", r.Code())
jkralik marked this conversation as resolved.
Show resolved Hide resolved
}
req.SetOptionUint32(message.Size1, uint32(payloadSize))

num := 0
buf := make([]byte, 1024)
Expand Down Expand Up @@ -259,27 +257,30 @@ func (b *BlockWise) Do(r Message, maxSzx SZX, maxMessageSize int, do func(req Me
return nil, fmt.Errorf("cannot encode block option(%v, %v, %v) to bw request: %w", szx, num, more, err)
}

req.SetOptionUint32(blockID, block)
req.SetOptionUint32(message.Block1, block)
resp, err := do(req)
if err != nil {
return nil, fmt.Errorf("cannot do bw request: %w", err)
}

if resp.Code() != codes.Continue {
block, err = resp.GetOptionUint32(message.Block1)
if err != nil {
return resp, nil
}
block, err = resp.GetOptionUint32(blockID)
if err != nil {
switch resp.Code() {
case codes.Continue, codes.Created, codes.Changed:
default:
return resp, nil
}

var newSzx SZX
var newNum int
newSzx, newNum, _, err = DecodeBlockOption(block)
if err != nil {
return resp, fmt.Errorf("cannot decode block option of bw response: %w", err)
}
func(n int) {
}(newNum)
if num != newNum {
return resp, fmt.Errorf("unexpected of acknowleged seqencenumber(%v != %v)", num, newNum)
}

num = num + newSzx.Size()/szx.Size()
szx = newSzx
Expand Down Expand Up @@ -312,8 +313,8 @@ func (w *writeRequestResponse) Message() Message {
return w.request
}

// WriteRequest sends an coap request via blockwise transfer.
func (b *BlockWise) WriteRequest(request Message, maxSZX SZX, maxMessageSize int, writeRequest func(r Message) error) error {
// WriteMessage sends an coap message via blockwise transfer.
func (b *BlockWise) WriteMessage(request Message, maxSZX SZX, maxMessageSize int, writeRequest func(r Message) error) error {
req := b.acquireMessage(request.Context())
req.SetCode(request.Code())
req.SetToken(request.Token())
Expand Down Expand Up @@ -435,7 +436,7 @@ func (b *BlockWise) Handle(w ResponseWriter, r Message, maxSZX SZX, maxMessageSi
err := b.handleReceivedMessage(w, r, maxSZX, maxMessageSize, next)
if err != nil {
b.sendEntityIncomplete(w, token)
b.errors(fmt.Errorf("handleReceivedMessage: %w", err))
b.errors(fmt.Errorf("handleReceivedMessage(%v): %w", r, err))
}
return
}
Expand All @@ -446,14 +447,14 @@ func (b *BlockWise) Handle(w ResponseWriter, r Message, maxSZX SZX, maxMessageSi
err := b.handleReceivedMessage(w, r, maxSZX, maxMessageSize, next)
if err != nil {
b.sendEntityIncomplete(w, token)
b.errors(fmt.Errorf("handleReceivedMessage: %w", err))
b.errors(fmt.Errorf("handleReceivedMessage(%v): %w", r, err))
}
return
}
more, err := b.continueSendingMessage(w, r, maxSZX, maxMessageSize, v.(*messageGuard))
if err != nil {
b.sendingMessagesCache.Delete(tokenStr)
b.errors(fmt.Errorf("continueSendingMessage: %w", err))
b.errors(fmt.Errorf("continueSendingMessage(%v): %w", r, err))
return
}
if b.autoCleanUpResponseCache && more == false {
Expand Down
Loading