-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add network device driver model, netdev
This PR adds a network device driver model called netdev. There will be a companion PR for TinyGo drivers to update the netdev drivers and network examples. This PR covers the core "net" package. An RFC for the work is here: #tinygo-org/drivers#487. Some things have changed from the RFC, but nothing major. The "net" package is a partial port of Go's "net" package, version 1.19.3. The src/net/README file has details on what is modified from Go's "net" package. Most "net" features are working as they would in normal Go. TCP/UDP/TLS protocol support is there. As well as HTTP client and server support. Standard Go network packages such as golang.org/x/net/websockets and Paho MQTT client work as-is. Other packages are likely to work as-is. Testing results are here (https://docs.google.com/spreadsheets/d/e/2PACX-1vT0cCjBvwXf9HJf6aJV2Sw198F2ief02gmbMV0sQocKT4y4RpfKv3dh6Jyew8lQW64FouZ8GwA2yjxI/pubhtml?gid=1013173032&single=true).
- Loading branch information
1 parent
aa038b7
commit fc9d818
Showing
7 changed files
with
104 additions
and
2 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 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,12 @@ | ||
// TINYGO: The following is copied and modified from Go 1.19.3 official implementation. | ||
|
||
// Copyright 2009 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package tls | ||
|
||
// ConnectionState records basic TLS details about the connection. | ||
type ConnectionState struct { | ||
// TINYGO: empty; TLS connection offloaded to device | ||
} |
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,63 @@ | ||
// TINYGO: The following is copied and modified from Go 1.19.3 official implementation. | ||
|
||
// Copyright 2009 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package tls partially implements TLS 1.2, as specified in RFC 5246, | ||
// and TLS 1.3, as specified in RFC 8446. | ||
package tls | ||
|
||
// BUG(agl): The crypto/tls package only implements some countermeasures | ||
// against Lucky13 attacks on CBC-mode encryption, and only on SHA1 | ||
// variants. See http://www.isg.rhul.ac.uk/tls/TLStiming.pdf and | ||
// https://www.imperialviolet.org/2013/02/04/luckythirteen.html. | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
// Client returns a new TLS client side connection | ||
// using conn as the underlying transport. | ||
// The config cannot be nil: users must set either ServerName or | ||
// InsecureSkipVerify in the config. | ||
func Client(conn net.Conn, config *Config) *net.TLSConn { | ||
panic("tls.Client() not implemented") | ||
return nil | ||
} | ||
|
||
// DialWithDialer connects to the given network address using dialer.Dial and | ||
// then initiates a TLS handshake, returning the resulting TLS connection. Any | ||
// timeout or deadline given in the dialer apply to connection and TLS | ||
// handshake as a whole. | ||
// | ||
// DialWithDialer interprets a nil configuration as equivalent to the zero | ||
// configuration; see the documentation of Config for the defaults. | ||
// | ||
// DialWithDialer uses context.Background internally; to specify the context, | ||
// use Dialer.DialContext with NetDialer set to the desired dialer. | ||
func DialWithDialer(dialer *net.Dialer, network, addr string, config *Config) (*net.TLSConn, error) { | ||
switch network { | ||
case "tcp", "tcp4": | ||
default: | ||
return nil, fmt.Errorf("Network %s not supported", network) | ||
} | ||
|
||
return net.DialTLS(addr) | ||
} | ||
|
||
// Dial connects to the given network address using net.Dial | ||
// and then initiates a TLS handshake, returning the resulting | ||
// TLS connection. | ||
// Dial interprets a nil configuration as equivalent to | ||
// the zero configuration; see the documentation of Config | ||
// for the defaults. | ||
func Dial(network, addr string, config *Config) (*net.TLSConn, error) { | ||
return DialWithDialer(new(net.Dialer), network, addr, config) | ||
} | ||
|
||
// Config is a placeholder for future compatibility with | ||
// tls.Config. | ||
type Config struct { | ||
} |
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 |
---|---|---|
|
@@ -53,7 +53,6 @@ const ( | |
DT_UNKNOWN = 0x0 | ||
DT_WHT = 0xe | ||
F_GETFL = 0x3 | ||
F_SETFL = 0x4 | ||
O_NONBLOCK = 0x4 | ||
) | ||
|
||
|
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