Unbewohnte
3 years ago
7 changed files with 125 additions and 6 deletions
@ -1,7 +1,56 @@
|
||||
package node |
||||
|
||||
import ( |
||||
"net" |
||||
|
||||
"github.com/Unbewohnte/ftu/protocol" |
||||
) |
||||
|
||||
type NodeInnerStates struct { |
||||
Connected bool |
||||
InTransfer bool |
||||
IsWaiting bool |
||||
Stopped bool |
||||
} |
||||
|
||||
type Security struct { |
||||
EncryptionKey []byte |
||||
} |
||||
|
||||
// Server and a client in one type !
|
||||
type Node struct { |
||||
conn net.Conn |
||||
packetPipe chan []protocol.Packet |
||||
State *NodeInnerStates |
||||
Security *Security |
||||
} |
||||
|
||||
// Creates a new either a server-side or client-side node
|
||||
func NewNode(options *NodeOptions) (*Node, error) { |
||||
|
||||
node := Node{} |
||||
return &node, nil |
||||
} |
||||
|
||||
func (node *Node) Connect(addr string, port uint) error { |
||||
return nil |
||||
} |
||||
|
||||
func (node *Node) Disconnect() error { |
||||
if node.State.Connected { |
||||
err := node.conn.Close() |
||||
if err != nil { |
||||
return err |
||||
} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (node *Node) Send(packet protocol.Packet) error { |
||||
return nil |
||||
} |
||||
|
||||
func (node *Node) Listen() error { |
||||
return nil |
||||
} |
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package node |
||||
|
||||
// Implementation for sender and receiver node
|
||||
import "github.com/Unbewohnte/ftu/protocol" |
||||
|
||||
// Implementation for sender and receiver nodes. [I`ll Probably remove it later. I don`t see the use-cases rn]
|
||||
type Noder interface { |
||||
Connect(addr string, port uint) error |
||||
Disconnect() error |
||||
Listen(dataPipe chan []byte) |
||||
Send(data []byte) error |
||||
Listen(packetPipe chan protocol.Packet) |
||||
Send(packet protocol.Packet) error |
||||
} |
||||
|
@ -0,0 +1,23 @@
|
||||
package node |
||||
|
||||
import ( |
||||
"github.com/Unbewohnte/ftu/fs" |
||||
"github.com/Unbewohnte/ftu/protocol" |
||||
) |
||||
|
||||
type ServerSideNodeOptions struct { |
||||
ServingDirectory *fs.Directory // Can be set to nil
|
||||
ServingFile *fs.File // Can be set to nil
|
||||
} |
||||
|
||||
type ClientSideNodeOptions struct { |
||||
DownloadsFolder *fs.Directory // Must be set during the Node creation, even if it will be changed afterwards
|
||||
} |
||||
|
||||
// Options to configure the node
|
||||
type NodeOptions struct { |
||||
WorkingPort uint |
||||
PacketPipe chan protocol.Packet |
||||
ServerSide *ServerSideNodeOptions |
||||
ClientSide *ClientSideNodeOptions |
||||
} |
Loading…
Reference in new issue