[PD1] Certs done
This commit is contained in:
parent
23584e2901
commit
2c4f1fd2fc
6 changed files with 104 additions and 29 deletions
|
@ -1,13 +1,21 @@
|
|||
package networking
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
)
|
||||
|
||||
|
||||
type ClientTLSConfigProvider interface {
|
||||
GetTLSConfigClient() *tls.Config
|
||||
}
|
||||
|
||||
type Client[T any] struct {
|
||||
Connection Connection[T]
|
||||
}
|
||||
|
||||
func NewClient[T any]() Client[T] {
|
||||
dialConn, err := net.Dial("tcp", "localhost:8080")
|
||||
func NewClient[T any](clientTLSConfigProvider ClientTLSConfigProvider) Client[T] {
|
||||
dialConn, err := tls.Dial("tcp", "localhost:8080", clientTLSConfigProvider.GetTLSConfigClient())
|
||||
if err != nil {
|
||||
panic("Could not open connection to server")
|
||||
}
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
package networking
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
type ServerTLSConfigProvider interface {
|
||||
GetServerTLSConfig() *tls.Config
|
||||
}
|
||||
|
||||
type Server[T any] struct {
|
||||
listener net.Listener
|
||||
C chan Connection[T]
|
||||
}
|
||||
|
||||
func NewServer[T any](port int) Server[T]{
|
||||
func NewServer[T any](serverTLSConfigProvider ServerTLSConfigProvider,port int) Server[T]{
|
||||
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
|
||||
listener, err := tls.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port), serverTLSConfigProvider.GetServerTLSConfig())
|
||||
if err != nil {
|
||||
panic("Server could not bind to address")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue