-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial yamux implementation * Implement per stream write buffers and per connection max write buffer size limit. * Make MuxHandler abstract. Move Mplex specific members to MplexHandler. Derive YamuxHandler from it * Refactor MuxHandler tests * Refactor MplexFrame, remove obsolete MuxFrame * Flush buffered writes in yamux on local disconnect --------- Co-authored-by: Anton Nashatyrev <[email protected]>
- Loading branch information
1 parent
f42740f
commit 8971b31
Showing
19 changed files
with
612 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2019 BLK Technologies Limited (web3labs.com). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package io.libp2p.mux.mplex | ||
|
||
import io.libp2p.mux.mplex.MplexFlag.Type.* | ||
|
||
/** | ||
* Contains all the permissible values for flags in the <code>mplex</code> protocol. | ||
*/ | ||
enum class MplexFlag( | ||
val value: Int, | ||
val type: Type | ||
) { | ||
NewStream(0, OPEN), | ||
MessageReceiver(1, DATA), | ||
MessageInitiator(2, DATA), | ||
CloseReceiver(3, CLOSE), | ||
CloseInitiator(4, CLOSE), | ||
ResetReceiver(5, RESET), | ||
ResetInitiator(6, RESET); | ||
|
||
enum class Type { | ||
OPEN, | ||
DATA, | ||
CLOSE, | ||
RESET | ||
} | ||
|
||
val isInitiator get() = value % 2 == 0 | ||
|
||
private val initiatorString get() = when (isInitiator) { | ||
true -> "init" | ||
false -> "resp" | ||
} | ||
|
||
override fun toString(): String = "$type($initiatorString)" | ||
|
||
companion object { | ||
private val valueToFlag = MplexFlag.values().associateBy { it.value } | ||
|
||
fun getByValue(flagValue: Int): MplexFlag = | ||
valueToFlag[flagValue] ?: throw IllegalArgumentException("Invalid Mplex stream tag: $flagValue") | ||
|
||
fun getByType(type: Type, initiator: Boolean): MplexFlag = | ||
when (type) { | ||
OPEN -> NewStream | ||
DATA -> if (initiator) MessageInitiator else MessageReceiver | ||
CLOSE -> if (initiator) CloseInitiator else CloseReceiver | ||
RESET -> if (initiator) ResetInitiator else ResetReceiver | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.libp2p.mux.yamux | ||
|
||
/** | ||
* Contains all the permissible values for flags in the <code>yamux</code> protocol. | ||
*/ | ||
object YamuxFlags { | ||
const val SYN = 1 | ||
const val ACK = 2 | ||
const val FIN = 4 | ||
const val RST = 8 | ||
} |
Oops, something went wrong.