Documentation
¶
Index ¶
- Constants
- func CalculateFileHash(filePath string) (string, error)
- func CheckFzfInstalled() error
- func CheckNativePickerAvailable() bool
- func CreateFzfCommand(startDir string) tea.Cmd
- func CreateNativeFilePickerCommand() tea.Cmd
- func EncodeFileMessage(msg *FileTransferMessage) ([]byte, error)
- func GenerateTransferID(peerID router.PeerID, fileName string) string
- func NewTUI(chat *Chat, myID router.PeerID) *model
- func ReadFzfResult(startDir string) (string, error)
- func ReadNativePickerResult() (string, error)
- func RunTUI(chat *Chat, myID router.PeerID) error
- func ValidateFileName(fileName string) error
- type Chat
- func (c *Chat) AddContact(hexID string, name string) error
- func (c *Chat) BlockContact(peerID router.PeerID) error
- func (c *Chat) Close() error
- func (c *Chat) Connect(hexID string) error
- func (c *Chat) DeleteContact(peerID router.PeerID) error
- func (c *Chat) Disconnect(peerID router.PeerID) error
- func (c *Chat) Events() <-chan ChatEvent
- func (c *Chat) GetContacts() ([]*Contact, error)
- func (c *Chat) GetMessages(peerID router.PeerID, limit int) ([]*Message, error)
- func (c *Chat) GetUnreadCount(peerID router.PeerID) (int, error)
- func (c *Chat) IsOnline(peerID router.PeerID) bool
- func (c *Chat) MarkAsRead(peerID router.PeerID) error
- func (c *Chat) RenameContact(peerID router.PeerID, newName string) error
- func (c *Chat) SearchMessages(query string, limit int) ([]*SearchResult, error)
- func (c *Chat) SendFile(peerID router.PeerID, filePath string) error
- func (c *Chat) SendMessage(peerID router.PeerID, content string) error
- func (c *Chat) UnblockContact(peerID router.PeerID) error
- type ChatEvent
- type ChatEventType
- type Contact
- type FilePickerModel
- type FileTransfer
- type FileTransferManager
- func (ftm *FileTransferManager) GetTransfer(transferID string) (*FileTransfer, bool)
- func (ftm *FileTransferManager) StartReceiving(peerID router.PeerID, msg *FileTransferMessage) (*FileTransfer, error)
- func (ftm *FileTransferManager) StartSending(peerID router.PeerID, filePath string) (*FileTransfer, error)
- type FileTransferMessage
- type FileTransferStatus
- type FileTransferType
- type Message
- type SearchResult
- type Storage
- func (s *Storage) AddContact(peerID router.PeerID, name string) error
- func (s *Storage) Close() error
- func (s *Storage) DeleteContact(peerID router.PeerID) error
- func (s *Storage) GetAllContacts() ([]*Contact, error)
- func (s *Storage) GetContact(peerID router.PeerID) (*Contact, error)
- func (s *Storage) GetFileTransfer(transferID string) (peerID router.PeerID, fileName string, fileSize int64, filePath string, ...)
- func (s *Storage) GetFileTransfers(peerID router.PeerID, limit int) ([]struct{ ... }, error)
- func (s *Storage) GetMessages(peerID router.PeerID, limit int) ([]*Message, error)
- func (s *Storage) GetUnreadCount(peerID router.PeerID) (int, error)
- func (s *Storage) MarkAsRead(peerID router.PeerID) error
- func (s *Storage) SaveFileTransfer(transferID string, peerID router.PeerID, fileName string, fileSize int64, ...) error
- func (s *Storage) SaveMessage(msg *Message) error
- func (s *Storage) SearchMessages(query string, limit int) ([]*SearchResult, error)
- func (s *Storage) SetBlocked(peerID router.PeerID, blocked bool) error
- func (s *Storage) SetNotificationsBlocked(peerID router.PeerID, blocked bool) error
- func (s *Storage) UpdateContactName(peerID router.PeerID, name string) error
- func (s *Storage) UpdateFileTransferProgress(transferID string, progress int) error
- func (s *Storage) UpdateFileTransferStatus(transferID string, status string, hash string) error
- func (s *Storage) UpdateLastSeen(peerID router.PeerID) error
Constants ¶
const ( MaxFileSize = 200 * 1024 * 1024 // 200 MB ChunkSize = 64 * 1024 // 64 KB chunks FileTransferV1 = "FILE_TRANSFER_V1" )
const ( MaxMessageSize = 10 * 1024 * 1024 // 10 MB - maximum message size MaxContactName = 256 // Maximum contact name length MaxContactCount = 10000 // Maximum number of contacts )
Security limits
Variables ¶
This section is empty.
Functions ¶
func CalculateFileHash ¶
CalculateFileHash calculates SHA256 hash of file
func CheckFzfInstalled ¶
func CheckFzfInstalled() error
CheckFzfInstalled checks if fzf and fd are installed
func CheckNativePickerAvailable ¶
func CheckNativePickerAvailable() bool
CheckNativePickerAvailable checks if native picker is available
func CreateFzfCommand ¶
CreateFzfCommand creates command to launch fzf+fd
func CreateNativeFilePickerCommand ¶
CreateNativeFilePickerCommand creates a command to launch the OS native file picker
func EncodeFileMessage ¶
func EncodeFileMessage(msg *FileTransferMessage) ([]byte, error)
EncodeFileMessage encodes file transfer message
func GenerateTransferID ¶
GenerateTransferID generates unique transfer ID
func ReadFzfResult ¶
ReadFzfResult reads the result from a temporary file
func ReadNativePickerResult ¶
ReadNativePickerResult reads the result from a temporary file
func ValidateFileName ¶
ValidateFileName checks file name for security
Types ¶
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
func (*Chat) AddContact ¶
AddContact adds new contact
func (*Chat) BlockContact ¶
BlockContact blocks contact and terminates connection
func (*Chat) DeleteContact ¶
DeleteContact deletes a contact and all conversation history
func (*Chat) Disconnect ¶
Disconnect terminates connection with contact
func (*Chat) GetContacts ¶
GetContacts returns all contacts
func (*Chat) GetMessages ¶
GetMessages returns messages with a contact
func (*Chat) GetUnreadCount ¶
GetUnreadCount returns the number of unread messages
func (*Chat) MarkAsRead ¶
MarkAsRead marks messages as read
func (*Chat) RenameContact ¶
RenameContact renames a contact
func (*Chat) SearchMessages ¶
func (c *Chat) SearchMessages(query string, limit int) ([]*SearchResult, error)
SearchMessages searches for messages containing the query string across all contacts
func (*Chat) SendMessage ¶
SendMessage sends message to contact
type ChatEvent ¶
type ChatEvent struct {
Type ChatEventType
PeerID router.PeerID
Message *Message
Contact *Contact
FileTransfer *FileTransfer
Error error
}
ChatEvent represents a chat event
type ChatEventType ¶
type ChatEventType uint8
ChatEventType defines chat event type
const ( ChatEventMessageReceived ChatEventType = iota ChatEventMessageSent ChatEventContactAdded ChatEventContactOnline ChatEventContactOffline ChatEventConnectionFailed ChatEventError ChatEventFileTransferStarted ChatEventFileTransferProgress ChatEventFileTransferCompleted ChatEventFileTransferFailed )
type Contact ¶
type Contact struct {
PeerID router.PeerID
Name string
AddedAt time.Time
LastSeen time.Time
IsBlocked bool
NotificationsBlocked bool // Block notifications from this contact
}
Contact represents a contact in address book
type FilePickerModel ¶
type FilePickerModel struct {
// contains filtered or unexported fields
}
FilePickerModel represents a file browser
func NewFilePicker ¶
func NewFilePicker(startDir string, onSelect func(string), onCancel func()) *FilePickerModel
NewFilePicker creates a new file browser
func (*FilePickerModel) Update ¶
func (fp *FilePickerModel) Update(msg tea.Msg) (*FilePickerModel, tea.Cmd)
Update handles events
func (*FilePickerModel) View ¶
func (fp *FilePickerModel) View() string
View renders the file browser
type FileTransfer ¶
type FileTransfer struct {
ID string
PeerID router.PeerID
FileName string
FileSize int64
FilePath string // File path (for sending or saving)
IsOutgoing bool
Status FileTransferStatus
Progress int // Completion percentage
ChunksRecv map[int]bool
TotalChunks int
File *os.File
Hash string
StartedAt time.Time
// contains filtered or unexported fields
}
FileTransfer represents an active file transfer
func (*FileTransfer) UpdateProgress ¶
func (ft *FileTransfer) UpdateProgress(chunksCompleted int)
UpdateProgress updates transfer progress
type FileTransferManager ¶
type FileTransferManager struct {
// contains filtered or unexported fields
}
FileTransferManager manages file transfers
func NewFileTransferManager ¶
func NewFileTransferManager(storage *Storage, dataDir string) *FileTransferManager
NewFileTransferManager creates a new transfer manager
func (*FileTransferManager) GetTransfer ¶
func (ftm *FileTransferManager) GetTransfer(transferID string) (*FileTransfer, bool)
GetTransfer returns transfer by ID
func (*FileTransferManager) StartReceiving ¶
func (ftm *FileTransferManager) StartReceiving(peerID router.PeerID, msg *FileTransferMessage) (*FileTransfer, error)
StartReceiving starts file receiving
func (*FileTransferManager) StartSending ¶
func (ftm *FileTransferManager) StartSending(peerID router.PeerID, filePath string) (*FileTransfer, error)
StartSending starts file sending
type FileTransferMessage ¶
type FileTransferMessage struct {
Type FileTransferType `json:"type"`
TransferID string `json:"transfer_id"` // Unique transfer ID
FileName string `json:"file_name"` // File name
FileSize int64 `json:"file_size"` // File size
MimeType string `json:"mime_type"` // MIME type
ChunkIndex int `json:"chunk_index"` // Chunk index
TotalChunks int `json:"total_chunks"` // Total chunks
Data []byte `json:"data"` // Chunk data
SHA256Hash string `json:"sha256_hash"` // SHA256 file hash
}
FileTransferMessage represents a file transfer message
func DecodeFileMessage ¶
func DecodeFileMessage(data []byte) (*FileTransferMessage, error)
DecodeFileMessage decodes file transfer message
type FileTransferStatus ¶
type FileTransferStatus string
FileTransferStatus defines transfer status
const ( FileTransferPending FileTransferStatus = "pending" FileTransferTransferring FileTransferStatus = "transferring" FileTransferCompleted FileTransferStatus = "completed" FileTransferFailed FileTransferStatus = "failed" FileTransferCancelled FileTransferStatus = "cancelled" )
type FileTransferType ¶
type FileTransferType uint8
FileTransferType defines file transfer message type
const ( FileTransferStart FileTransferType = iota // Start of transfer (metadata) FileTransferChunk // Data chunk FileTransferEnd // End of transfer (with hash) FileTransferAck // Acknowledgment of chunk receipt FileTransferCancel // Transfer cancellation )
type Message ¶
type Message struct {
ID int64
PeerID router.PeerID
Content string
Timestamp time.Time
IsOutgoing bool // true if we sent, false if received
IsRead bool
}
Message represents a message in chat
type SearchResult ¶
SearchResult represents a search result with contact info
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage manages message and contact storage
func (*Storage) AddContact ¶
AddContact adds a new contact
func (*Storage) DeleteContact ¶
DeleteContact deletes contact and all conversation history
func (*Storage) GetAllContacts ¶
GetAllContacts returns all contacts
func (*Storage) GetContact ¶
GetContact returns contact by ID
func (*Storage) GetFileTransfer ¶
func (s *Storage) GetFileTransfer(transferID string) (peerID router.PeerID, fileName string, fileSize int64, filePath string, isOutgoing bool, status string, progress int, err error)
GetFileTransfer returns transfer information by ID
func (*Storage) GetFileTransfers ¶
func (s *Storage) GetFileTransfers(peerID router.PeerID, limit int) ([]struct { TransferID string FileName string FileSize int64 IsOutgoing bool Status string Progress int StartedAt time.Time CompletedAt *time.Time }, error)
GetFileTransfers returns list of transfers for contact
func (*Storage) GetMessages ¶
GetMessages returns messages with a contact
func (*Storage) GetUnreadCount ¶
GetUnreadCount returns the number of unread messages from contact
func (*Storage) MarkAsRead ¶
MarkAsRead marks all messages from contact as read
func (*Storage) SaveFileTransfer ¶
func (s *Storage) SaveFileTransfer(transferID string, peerID router.PeerID, fileName string, fileSize int64, filePath string, isOutgoing bool, status string) error
SaveFileTransfer saves file transfer information
func (*Storage) SaveMessage ¶
SaveMessage saves a message
func (*Storage) SearchMessages ¶
func (s *Storage) SearchMessages(query string, limit int) ([]*SearchResult, error)
SearchMessages searches for messages containing the query string Returns results from all contacts, sorted by timestamp (newest first)
func (*Storage) SetBlocked ¶
SetBlocked sets contact blocked status
func (*Storage) SetNotificationsBlocked ¶
SetNotificationsBlocked sets notification blocking for contact
func (*Storage) UpdateContactName ¶
UpdateContactName updates contact name
func (*Storage) UpdateFileTransferProgress ¶
UpdateFileTransferProgress updates transfer progress
func (*Storage) UpdateFileTransferStatus ¶
UpdateFileTransferStatus updates transfer status