5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-09-16 18:29:35 +00:00

Added two new methods to mobile package (#974)

* Added two new methods

In order to implement https://github.com/yggdrasil-network/yggdrasil-android/issues/25 we need these new methods.

* Renamed methods, changed comments
This commit is contained in:
Revertron 2022-11-01 13:10:50 +01:00 committed by GitHub
parent cfa293d189
commit ee33bd248f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,6 +115,18 @@ func (m *Yggdrasil) Send(p []byte) error {
return nil
}
// Send sends a packet from given buffer to Yggdrasil. From first byte up to length.
func (m *Yggdrasil) SendBuffer(p []byte, length int) error {
if m.iprwc == nil {
return nil
}
if len(p) < length {
return nil
}
_, _ = m.iprwc.Write(p[:length])
return nil
}
// Recv waits for and reads a packet coming from Yggdrasil. It
// will be a fully formed IPv6 packet
func (m *Yggdrasil) Recv() ([]byte, error) {
@ -126,6 +138,15 @@ func (m *Yggdrasil) Recv() ([]byte, error) {
return buf[:n], nil
}
// Recv waits for and reads a packet coming from Yggdrasil to given buffer, returning size of packet
func (m *Yggdrasil) RecvBuffer(buf []byte) (int, error) {
if m.iprwc == nil {
return 0, nil
}
n, _ := m.iprwc.Read(buf)
return n, nil
}
// Stop the mobile Yggdrasil instance
func (m *Yggdrasil) Stop() error {
logger := log.New(m.log, "", 0)